Assembly Language Programming
Write a complete assembly program that inputs a small signed integer n, whose value can fit within 8 bits, and outputs the value of the expression n2 – n + 6.
(This is not C++ or Java. Has to be masm file)
Code:
find:
PUSH %BP
MOV %SP, %BP
@find_body:
MUL 8(%BP), 8(%BP), %0
SUB %0, 8(%BP), %0
ADD %0, $6, %0
SUB %SP, $4, %SP
MOV %0, -4(%BP)
MOV -4(%BP), %13
JMP @find_exit
@find_exit:
MOV %BP, %SP
POP %BP
RET
main:
PUSH %BP
MOV %SP, %BP
@main_body:
PUSH $6
CALL find
ADD %SP, $4, %SP
MOV $0, %13
JMP @main_exit
@main_exit:
MOV %BP, %SP
POP %BP
RET
Hope this helps.
Get Answers For Free
Most questions answered within 1 hours.