Requirements: 1· (8 points) Write a program that clears the screen and prompts t
ID: 3707393 • Letter: R
Question
Requirements: 1· (8 points) Write a program that clears the screen and prompts the user to enter three signed integers Enter Signed Integer: Assign those values to val2, val3, and val4 - vall, val2, val3 and val4 are 32-bit memory signed integers - Pass those values to a subroutine that implements the following expression vall -(val2 val3) * (val4 / val2) +(val3 * 3) To access the values in the caller frame, use EBP (remember EBP is created at the callee side) The calculated expression result needs to be assigned to vall at the caller side. The calculated expression result needs to be displayed on console screen from main subroutine Name the subroutine IntegerArithmeticProc. When calling or creating the Integer ArithmeticProc subroutine, you are not allowed to use any of the following directives: invoke, addr, proc with lists, and proto or proto with lists Use the appropriate multiplication and division instructions Use the CBW, CWD, or CDQ instructions when needed. For (val3 *3), you must use the instruction of the two operands format Run your program using the debugger to verify your answers Use Step Into instead of Step Over to keep track of the stack, ESP, EBP, EIP during debugging. To access the stack memory, copy the value of ESP from the register window and past it in the search text box in the memory window. *Explanation / Answer
Code:
DATA SEGMENT
msg1 DB "Enter Signed integers:"
val1 DW ?
val2 DW ?
val3 DW ?
val4 DW ?
CODE SEGMENT
mov ax,@data ;get data segment address
mov ds,ax ;initialize ds
;set the cursor position to the middle of the screen(25rowsx80columns)
MOV ah, 2
MOV bh, 1 ; page number
MOV dh, 12 ; middle row
MOV dl, 40 ; middle column
INT 10h
LEA DX, msg1 ; prompt user for input
MOV AH, 9
INT 21H
MOV ah, 1
INT 21h
MOV val2,AL
MOV ah, 2
INT 21h
MOV val3,AL
MOV ah, 3
INT 21h
MOV val4,AL
MOV EAX, val1 ; save final result in eax
; push parameters onto the stack from right to left
PUSHL val4
PUSHL val3
PUSHL val2
CALL IntegerArithmeticProc
STORE EAX, val1 ; Store final output in val1
IntegerArithmeticProc:
PUSH EBP
MOV EBP, ESP
MOV EBX, [EBP+8] ; EBX = val4
MOV ECX, [EBP+12] ; ECX = val3
MOV EDX, [EBP+16] ; EDX = val2
DIV EBX, EDX ; EBX = EBX/EDX = val4/val2
SUB EDX, ECX ; EDX = EDX-ECX = val2-val3
MULTI ECX, #3 ; ECX = ECX *3 = val3*3
MULTI EDX, EBX
SUB EDX, ECX
MOV EAX, EDX ; Final result in EAX
MOV ESP, EBP
POP EBP
RET ; Return
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.