1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
;importing exter C symbol
extern printf
;declaring variables
segment .data
;variable1 takes 1 as a value
value1: dd 1h ; value1 is 32 Bits containing the hexa 1
value2: dd 2h ; value2 is 32 Bits containing the hexa 2
message_add: db 'Addition Result:', 10, 0
message_inc: db 'Increase one unit:', 10, 0
format_d: db '%d', 10, 0 ; "%d\n" to call printf("%d\n", eax);
;entry point for main function
global main
;start assembly program
section .text
;coding the _main symbol
main:
;pushing the message_add on the stack
push message_add
;calling the printf in order to display the add message
call printf
;taking the EAX off
pop EAX
;put the value of the value1 variable into the EAX registre
mov EAX, [value1]
;add the value of value2 variable into the EAX restre
add EAX, [value2]
;pushing the EAX value on the stack
push EAX
;pushing the value1 variable on the stack
push format_d
;calling the _printf C function
call printf
;cleaning up the stack by unstacking the hello variable on the EAX register
pop EAX ;gets the '%d', 10, 0 value out
pop EAX ;gets the 3 value out
;****************
mov EBX, message_inc
;push message_inc on the stack
push EBX
;call the printf C function
call printf
;cleaning up the stack
pop EBX
;****************
;put the value of the value1 variable into the EAX registre
mov EAX, [value1]
;add the value of value2 variable into the EAX restre
add EAX, [value2]
;increase the EAX one unit: EAX++
inc EAX
;push the incremented number on the stack
push EAX
;push the format string on the stack
push format_d
;call the printf C function
call printf
;cleaning up the stack
pop EAX
pop EAX
;exiting from _main symbol
ret |
Partager