FilipBogo

Correct h2 ex1

Oct 21st, 2024
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Z80 Assembler 1.20 KB | Source Code | 0 0
  1. bits 32 ; assembling for the 32 bits architecture
  2.  
  3. ; declare the EntryPoint (a label defining the very first instruction of the program)
  4. global start        
  5.  
  6. ; declare external functions needed by our program
  7. extern exit               ; tell nasm that exit exists even if we won't be defining it
  8. import exit msvcrt.dll    ; exit is a function that ends the calling process. It is defined in msvcrt.dll
  9.                           ; msvcrt.dll contains exit, printf and all the other important C-runtime specific functions
  10.  
  11. ; our data is declared here (the variables needed by our program)
  12. segment data use32 class=data
  13.     ;a - byte, b - word, c - double word, d - qword - Unsigned representation
  14.     ;(c-a) + (b - d) +d = c-a+b
  15.     a db 2
  16.     b dw 10
  17.     c dd 15
  18.     d dq 5
  19.     v1 resd 1
  20. ; our code starts here
  21. segment code use32 class=code
  22.     start:
  23.         ; ...
  24.         mov eax,0
  25.         mov ebx,0
  26.         mov ecx,0
  27.         mov edx,0
  28.         mov eax,[c]
  29.         mov bx,[b]
  30.         mov cl,[a]
  31.         sub bx,cx
  32.         add eax,ebx
  33.         ; exit(0)
  34.         push    dword 0      ; push the parameter for exit onto the stack
  35.         call    [exit]       ; call exit to terminate the program
  36.  
Advertisement
Add Comment
Please, Sign In to add comment