48 lines
1.3 KiB
NASM
48 lines
1.3 KiB
NASM
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 127f5678h,0abcdabcdh
|
|
l equ $-$$
|
|
b resb l
|
|
|
|
; our code starts here
|
|
segment code use32 class=code
|
|
start:
|
|
; ...
|
|
mov ECX,l
|
|
mov ESI,a
|
|
mov EDI,b
|
|
CLD
|
|
|
|
label:
|
|
LODSB
|
|
cbw
|
|
mov BX,AX
|
|
LODSB
|
|
cbw
|
|
mov DX,AX
|
|
LODSB
|
|
cbw
|
|
add BX,AX
|
|
LODSB
|
|
cbw
|
|
add AX,DX
|
|
rol EAX,16
|
|
mov AX,BX
|
|
STOSD
|
|
sub ECX,4
|
|
jg label
|
|
; exit(0)
|
|
push dword 0 ; push the parameter for exit onto the stack
|
|
call [exit] ; call exit to terminate the program
|