Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write and test the absolution value function in two linked files. Your solution

ID: 3737252 • Letter: W

Question

Write and test the absolution value function in two linked files. Your solution must be made up of a function called ‘absval’ that accepts a 32-bit signed integer in register $a0 and returns its absolute value as a 32-bit integer in $v0. Your solution must also include an assembly 'main' program that accepts an integer from the user, calls the absval function and prints the resulting value. Prompt the user for each entered integer and label your output.

Do not use the abs pseudo-instruction. Write the code to compute the absolute value.

Submit the Following File(s):

abs_main.asm, absval.asm

Required Input:

A signed 32-bit integer.

Required Output:

Your output should look something like the following example.

Explanation / Answer

CODE

.DATA

num DB                  DUP(?)                                                                       

inp DB                  "Enter an integer : $"

out       DB                  "The absolute value is : $"

.MAIN

MOV AX,DATA

MOV DS,AX

LEA    DX,inp

MOV AH,9

INT 21H

MOV num, AL

LEA $a0, num

PUSH $a0

call       absval

           

LEA DX,out

MOV AH,9

INT     21H

MOV DL, $v0

INT 21H

absval:

PUSH ebp

MOV ebp, esp

; abs(n) = (n xor (n>>31)) - (n>>31)

SRA $a1, $a0,31

XOR $a0, $a0, $a1

SUB $v0, $a0, $a1              

MOV esp, ebp

POP ebp

ret

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote