School Commit Init
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
bits 32 ; assembling for the 32 bits architecture
|
||||
|
||||
; declare the EntryPoint (a label defining the very first instruction of the program)
|
||||
global start
|
||||
|
||||
; declare external functions needed by our program
|
||||
extern exit,fopen,fclose,printf,fread,strchr ; tell nasm that exit exists even if we won't be defining it
|
||||
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
|
||||
import fopen msvcrt.dll
|
||||
import fclose msvcrt.dll
|
||||
import printf msvcrt.dll
|
||||
import fread msvcrt.dll
|
||||
import strchr msvcrt.dll
|
||||
|
||||
|
||||
|
||||
; our data is declared here (the variables needed by our program)
|
||||
|
||||
|
||||
;A text file is given. Read the content of the file, count the number of vowels and display the result on the screen. The name of text file is defined in the data segment.
|
||||
|
||||
segment data use32 class=data
|
||||
; ...
|
||||
file_path db "text.txt",0
|
||||
access_mode db "r",0
|
||||
vowels db "aeiouAEIOU",0
|
||||
message db "The number of vowels in the file is: %d",0
|
||||
file dd 0
|
||||
a db 0
|
||||
count dd 0
|
||||
|
||||
; our code starts here
|
||||
segment code use32 class=code
|
||||
start:
|
||||
; ...
|
||||
push dword access_mode
|
||||
push dword file_path
|
||||
call [fopen]
|
||||
add ESP,4*2
|
||||
cmp EAX,0
|
||||
jz end
|
||||
mov [file],EAX
|
||||
|
||||
push dword [file]
|
||||
push dword 1
|
||||
push dword 1
|
||||
push dword a
|
||||
loop_label:
|
||||
call [fread]
|
||||
cmp EAX,0
|
||||
jz done
|
||||
push dword [a]
|
||||
push dword vowels
|
||||
call [strchr]
|
||||
add ESP,4*2
|
||||
cmp EAX,0
|
||||
jz loop_label
|
||||
inc dword [count]
|
||||
jmp loop_label
|
||||
done:
|
||||
add ESP,4*4
|
||||
; exit(0)
|
||||
push dword [file]
|
||||
call [fclose]
|
||||
add ESP,4*1
|
||||
push dword [count]
|
||||
push dword message
|
||||
call [printf]
|
||||
add ESP,4*2
|
||||
end:
|
||||
push dword 0 ; push the parameter for exit onto the stack
|
||||
call [exit] ; call exit to terminate the program
|
||||
@@ -0,0 +1 @@
|
||||
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
||||
@@ -0,0 +1,86 @@
|
||||
bits 32 ; assembling for the 32 bits architecture
|
||||
|
||||
; declare the EntryPoint (a label defining the very first instruction of the program)
|
||||
global start
|
||||
|
||||
; declare external functions needed by our program
|
||||
extern exit,fopen,fclose,printf,fread ; tell nasm that exit exists even if we won't be defining it
|
||||
import exit msvcrt.dll ; exit is a function that ends the calling process. It is defined in msvcrt.dll
|
||||
import fopen msvcrt.dll
|
||||
import fclose msvcrt.dll
|
||||
import printf msvcrt.dll
|
||||
import fread msvcrt.dll
|
||||
|
||||
|
||||
|
||||
; our data is declared here (the variables needed by our program)
|
||||
|
||||
|
||||
;A text file is given. Read the content of the file, count the number of letters 'y' and 'z' and display the values on the screen. The file name is defined in the data segment.
|
||||
|
||||
segment data use32 class=data
|
||||
; ...
|
||||
file_path db "text.txt",0
|
||||
access_mode db "r",0
|
||||
message db `The number of 'y' in the file is: %d\nThe number of 'z' in the file is: %d`,0
|
||||
file dd 0
|
||||
a db 0
|
||||
count_y dd 0
|
||||
count_z dd 0
|
||||
|
||||
; our code starts here
|
||||
segment code use32 class=code
|
||||
start:
|
||||
; ...
|
||||
push dword access_mode
|
||||
push dword file_path
|
||||
call [fopen]
|
||||
add ESP,4*2
|
||||
cmp EAX,0
|
||||
jz end
|
||||
mov [file],EAX
|
||||
|
||||
push dword [file]
|
||||
push dword 1
|
||||
push dword 1
|
||||
push dword a
|
||||
|
||||
loop_label:
|
||||
call [fread]
|
||||
cmp EAX,0
|
||||
jz done
|
||||
|
||||
cmp byte [a],"y"
|
||||
jz inc_y
|
||||
cmp byte [a],"Y"
|
||||
jz inc_y
|
||||
|
||||
cmp byte [a],"z"
|
||||
jz inc_z
|
||||
cmp byte [a],"Z"
|
||||
jz inc_z
|
||||
|
||||
jmp loop_label
|
||||
|
||||
inc_y:
|
||||
inc dword [count_y]
|
||||
jmp loop_label
|
||||
|
||||
inc_z:
|
||||
inc dword [count_z]
|
||||
jmp loop_label
|
||||
|
||||
done:
|
||||
add ESP,4*4
|
||||
push dword [file]
|
||||
call [fclose]
|
||||
add ESP,4*1
|
||||
|
||||
push dword [count_z]
|
||||
push dword [count_y]
|
||||
push dword message
|
||||
call [printf]
|
||||
add ESP,4*3
|
||||
end:
|
||||
push dword 0 ; push the parameter for exit onto the stack
|
||||
call [exit] ; call exit to terminate the program
|
||||
@@ -0,0 +1 @@
|
||||
But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure? On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee
|
||||
Reference in New Issue
Block a user