Code:: DB DB DB DB DB

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

CODE:

global _main
extern _printf ; import external functionality
extern _scanf ; import external functionality
section .data
message1 db "Enter first number: ", 0 ; Initialize variable for prompt
message
message2 db "Enter second number: ", 0
formatIn db '%d', 0 ; Initialize variable for user input format
formatOut db '%d', 10, 0 ; Initialize variable for output format
show db "Sum: ", 0 ; Initialize variable for the output message

section .bss
firstInt resb 4 ; declare 4 bytes sized variable
secondInt resb 4 ; declare 4 bytes sized variable
section .text
_main:
; display the first prompt message
push message1
call _printf
pop eax
; Wait for the user input and store it
; in the variable firstInt with an integer format
push firstInt
push formatIn
call _scanf
pop eax
pop eax
; display the second prompt message
push message2
call _printf
pop eax
; Wait for the user input and store it
; in the variable secondInt with an integer format
push secondInt
push formatIn
call _scanf
pop eax
pop eax

; display the output message


push show
call _printf
pop eax
; add the two integer
mov ebx, dword [firstInt] ; move the value of firstInt to ebx register
mov ecx, dword [secondInt] ; move the value of secondInt to ecx register
add ebx, ecx ; add the value of ebx register and ecx register together
; display the sum
push ebx
push formatOut
call _printf

; reset the registers to their initial state


pop ecx
pop ebx
mov eax, 0
ret

OUTPUT:

You might also like