Write the following subroutine in x86 assembly: Subroutine arguments are passed
ID: 3679243 • Letter: W
Question
Write the following subroutine in x86 assembly: Subroutine arguments are passed on the stack, and can be accessed within the body of the subroutine starting at address EBP+8. At the start of each subroutine: Copy the current value of the stack pointer (ESP) to EBP Create space within the stack for each local variable by subtracting the appropriate value from ESP. For example, if your function uses four integer local variables, each of which contains four bytes, subtract 16 from ESP. Local variables can then be accessed starting at the address EBP-4. See Lectures 14 and 16-18 for more details on subroutines, the x86 architecture, and the conversion from high-level concepts to low-level assembly.Explanation / Answer
DATA SEGMENT
NUM1 DB ?
NUM2 DB ?
RESULT DB ?
MSG1 DB 10,13,"ENTER FIRST NUMBER TO ADD : $"
MSG2 DB 10,13,"ENTER SECOND NUMBER TO ADD : $"
MSG3 DB 10,13,"ENTER third NUMBER TO ADD : $"
MSG4 DB 10,13,"RESULT OF ADDITION IS : $"
ENDS
CODE SEGMENT
ASSUME DS:DATA CS:CODE
START:
MOV AX,DATA
MOV DS,AX
LEA DX,MSG1
MOV AH,9
INT 21H
MOV AH,1
INT 21H
SUB AL,30H
MOV NUM1,AL
LEA DX,MSG2
MOV AH,9
INT 21H
MOV AH,1
INT 21H
SUB AL,30H
MOV NUM2,AL
LEA DX,MSG3
MOV AH,9
INT 21H
MOV AH,1
INT 21H
SUB AL,30H
MOV NUM3,AL
ADD AL,NUM1
MOV RESULT,AL
MOV AH,0
AAA
ADD AH,30H
ADD AL,30H
MOV BX,AX
MOV CX,BX
ADD CX,NUM3
ADD BX,NUM3
ADD AX,BX
LEA DX,MSG4
MOV AH,9
INT 21H
MOV AH,2
MOV DL,AH
INT 21H
MOV AH,2
MOV DL,AL
INT 21H
MOV AH,4CH
INT 21H
ENDS
END START
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.