Question: TITLE ArthmeticsOn 1 4 Bytes ; This program adds and subtracts 1 4 - byte ( 1 1 2 - bit ) integers. ; Name:
TITLE ArthmeticsOnBytes
; This program adds and subtracts byte bit integers.
; Name: Dhruv Patel
; CPEN
; Date:
INCLUDE Irvineinc
data
bigVal BYTE hDhDhDhhDhBAh, hChBhhhhCh
bigVal BYTE AhFFhhAEh, hAhECh, CAh, ChAhChhEhDh
bigVal BYTE hhAhFAh, EFh, hDhhEhACh, EhBhEhCh
bigVal BYTE ECh, hhhBDhAFh, AhFhChDhChhAhAh
result BYTE DUP
result BYTE DUP
code
main PROC
; Call the subprogram to perform addition
mov esi, OFFSET bigVal ; Load offset of bigVal into ESI
mov edi, OFFSET bigVal ; Load offset of bigVal into EDI
mov ebx, OFFSET result ; Load offset of result into EBX
mov ecx, ; Set operation selector to addition
call subOperation ; Call subprogram
; Display result
mov esi, OFFSET result
mov ecx,
call DumpMem
call DumpRegs
; Call the subprogram to perform subtraction
mov esi, OFFSET bigVal ; Load offset of bigVal into ESI
mov edi, OFFSET bigVal ; Load offset of bigVal into EDI
mov ebx, OFFSET result ; Load offset of result into EBX
mov ecx, ; Set operation selector to subtraction
call subOperation ; Call subprogram
; Display result
mov esi, OFFSET result
mov ecx,
call DumpMem
call DumpRegs
main ENDP
subOperation PROC
pushad ; Save all generalpurpose registers
mov edx, ; Clear EDX for carryborrow
mov ecx, ; Set counter for bytes
performLoop:
mov alesi ; Load byte from first operand
mov bledi ; Load byte from second operand
cmp ecx,
jne checkOperation
; Perform addition with carry
add al bl
add dl
jmp storeResult
checkOperation:
cmp ecx,
je subBytes
; Perform addition with carry
add al bl
add dl
jmp storeResult
subBytes:
; Perform subtraction with borrow
sub al bl
sub dl
storeResult:
mov ebx al ; Store the result byte
inc esi ; Move to the next byte in first operand
inc edi ; Move to the next byte in second operand
inc ebx ; Move to the next byte in result
loop performLoop ; Repeat for all bytes
popad ; Restore all generalpurpose registers
ret
subOperation ENDP
END main
main ENDP
Modify this based off this question: It is important to keep in mind that on Intel microprocessorbased systems,
multibyte numbers are stored in memory least significant byte firstat the lowest
numbered memory address akalittleendian order. To get the correct answer, we
must start by adding or subtracting the least significant portion of the operands and
work toward the most significant portion of the operands not the other way around.
For the purposes of this assignment, all operands used in the computations, and all
results, must be stored in memory in littleendian format. You will have to think about
what this entails for reading and storing the bytes.
Write an assembly language program consisting of a main program and a
subprogram a second, separate procedure in the same file to be called from the main
procedure The purpose of the second procedure is to perform addition or subtraction
on bit unsigned integers each number is bytes stored in memory.
Communication between the main program and the called procedure is to be
done purely through CPU registers you will need to choose four:
A CPU register must be used to pass the memory offset of the first operand to the
subprogram.
A second register must be used to pass the offset of the second operand to the
subprogram.
A third register to pass the offset of the location where the result will be stored.
The called procedure should use only the information passed from the main program in
these three registers to locate the two source and one destination operands in memory;
do not refer to these variables by name anywhere within the subprogram
A fourth register is to be used as an operation selector to specify whether to add or
subtract the two operands. If this register contains the operands are to be added; if it
contains any other value, the operands are to be subtracted.
Use assembler directives within your data segment to declare storage for and initialize
the test variables given below. The main program should call the subprogram twice:
once to add: bigVal bigVal
and a second time to subtract: bigVal bigVal
bigValcbcbaddded
bigValdecaccaecaaeffa
bigVal cebeacedeffaa
bigValaacdcfaafbd
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
