School Commit Init
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
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 ; 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
|
||||
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
|
||||
|
||||
; our data is declared here (the variables needed by our program)
|
||||
segment data use32 class=data
|
||||
a db 2
|
||||
b db 2
|
||||
c db 3
|
||||
d db 4
|
||||
x resb 1
|
||||
|
||||
; our code starts here
|
||||
segment code use32 class=code
|
||||
start:
|
||||
; ...
|
||||
mov al,[a]
|
||||
add al,[b]
|
||||
mul byte [c]
|
||||
div byte [d]
|
||||
mov [x],al
|
||||
; exit(0)
|
||||
push dword 0 ; push the parameter for exit onto the stack
|
||||
call [exit] ; call exit to terminate the program
|
||||
@@ -0,0 +1,36 @@
|
||||
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 ; 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
|
||||
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
|
||||
|
||||
; our data is declared here (the variables needed by our program)
|
||||
segment data use32 class=data
|
||||
; ...
|
||||
a db 10
|
||||
b db 2
|
||||
c db 3
|
||||
d db 4
|
||||
x resb 1
|
||||
|
||||
; our code starts here
|
||||
segment code use32 class=code
|
||||
start:
|
||||
; ...
|
||||
mov al,[b]
|
||||
mul byte [c]
|
||||
mov bl,[a]
|
||||
mov bh,0
|
||||
sub bx,ax
|
||||
mov ax,bx
|
||||
div byte [d]
|
||||
mov [x],al
|
||||
|
||||
|
||||
; exit(0)
|
||||
push dword 0 ; push the parameter for exit onto the stack
|
||||
call [exit] ; call exit to terminate the program
|
||||
@@ -0,0 +1,35 @@
|
||||
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 ; 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
|
||||
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
|
||||
|
||||
; our data is declared here (the variables needed by our program)
|
||||
segment data use32 class=data
|
||||
; ...
|
||||
a db 10
|
||||
b dw 2
|
||||
c db 3
|
||||
d db 4
|
||||
x resw 1
|
||||
|
||||
; our code starts here
|
||||
segment code use32 class=code
|
||||
start:
|
||||
; ...
|
||||
mov ah,0
|
||||
mov al,[a]
|
||||
mul word [b]
|
||||
mov bl,[d]
|
||||
mov bh,0
|
||||
div bx
|
||||
mov bl,[c]
|
||||
sub ax,bx
|
||||
mov [x],ax
|
||||
; exit(0)
|
||||
push dword 0 ; push the parameter for exit onto the stack
|
||||
call [exit] ; call exit to terminate the program
|
||||
@@ -0,0 +1,56 @@
|
||||
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 ; 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
|
||||
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
|
||||
|
||||
; our data is declared here (the variables needed by our program)
|
||||
segment data use32 class=data
|
||||
; ...
|
||||
a db 10
|
||||
b dw 2
|
||||
c dd 3
|
||||
d db 4
|
||||
f dw 1
|
||||
g dw 2
|
||||
x dq 2
|
||||
|
||||
|
||||
|
||||
; our code starts here
|
||||
segment code use32 class=code
|
||||
start:
|
||||
; ...
|
||||
mov al,[a] ;AL=a
|
||||
cbw ;AX=a
|
||||
imul word [b] ;DX:AX=a*b
|
||||
push dx ;stack: dx,
|
||||
push ax ;stack: dx,ax
|
||||
mov al,[d] ;AL=d
|
||||
cbw ;AX=d
|
||||
cwde ;EAX=d
|
||||
mov ecx,[c] ;ECX=c
|
||||
sub ecx,eax ;ECX=c-d
|
||||
pop eax ;EAX=a*b , stack:
|
||||
cdq ;EDX:EAX=a*b
|
||||
idiv dword ecx ;EAX=(a*b)/(c-d)
|
||||
mov ecx,eax ;ECX=(a*b)/(c-d)
|
||||
mov ax,[f] ;AX=f
|
||||
imul word [g] ;DX:AX=f*g
|
||||
push dx ;stack: DX
|
||||
push ax ;stack: DX,AX
|
||||
pop eax ;EAX=f*g , stack:
|
||||
add eax,ecx ;EAX=(a*b)/(c-d)+f*g
|
||||
cdq ;EDX:EAX=(a*b)/(c-d)+f*g
|
||||
add [x],eax
|
||||
adc [x+4],edx
|
||||
|
||||
|
||||
|
||||
; exit(0)
|
||||
push dword 0 ; push the parameter for exit onto the stack
|
||||
call [exit] ; call exit to terminate the program
|
||||
@@ -0,0 +1,44 @@
|
||||
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 ; 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
|
||||
; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
|
||||
|
||||
; our data is declared here (the variables needed by our program)
|
||||
segment data use32 class=data
|
||||
a dd 1
|
||||
b db 1
|
||||
c dw 1
|
||||
d dw 1
|
||||
x resd 1
|
||||
|
||||
; our code starts here
|
||||
segment code use32 class=code
|
||||
start:
|
||||
mov ax,[a] ;AX=a-low
|
||||
mov dx,[a+2] ;DX=a-high DX:AX=a-low
|
||||
mov bx,2 ;BX=2
|
||||
idiv bx ;AX=a/2
|
||||
mov dx,ax ;DX=a/2
|
||||
mov al,[b] ;AL=b
|
||||
mov bl,3 ;BL=3
|
||||
imul bl ;AX=b*3
|
||||
add dx,ax
|
||||
mov ax,[c]
|
||||
imul word [d]
|
||||
push dx
|
||||
push ax
|
||||
pop eax
|
||||
mov eax,ecx
|
||||
mov ax,dx
|
||||
cwde
|
||||
sub eax,ecx
|
||||
add eax,100
|
||||
mov [x],eax
|
||||
; exit(0)
|
||||
push dword 0 ; push the parameter for exit onto the stack
|
||||
call [exit] ; call exit to terminate the program
|
||||
Reference in New Issue
Block a user