Question: TITLE ArthmeticsOn 1 4 Bytes ; This program adds and subtracts 1 4 - byte ( 1 1 2 - bit ) integers. ; Name:

TITLE ArthmeticsOn14Bytes
; This program adds and subtracts 14-byte (112-bit) integers.
; Name: Dhruv Patel
; CPEN 3710
; Date: 10/2/24
INCLUDE Irvine32.inc
.data
bigVal1 BYTE 29h,2Dh,6Dh,3Dh,56h,9Dh,0BAh, 33h,3Ch,0B7h,07h,32h,07h,9Ch
bigVal2 BYTE 0A2h,0FFh,54h,0AEh, 55h,0A7h,0ECh, 0CAh, 0C1h,3Ah,0C4h,74h,0Eh,3Dh
bigVal3 BYTE 31h,95h,7Ah,0FAh, 0EFh, 23h,4Dh,84h,0E3h,0ACh, 3Eh,0B5h,0E4h,0C1h
bigVal4 BYTE 0ECh, 47h,13h,17h,0BDh,0AFh, 2Ah,6Fh,0C5h,7Dh,0C5h,03h,0A0h,5Ah
result1 BYTE 14 DUP(?)
result2 BYTE 14 DUP(?)
.code
main PROC
; Call the subprogram to perform addition
mov esi, OFFSET bigVal1 ; Load offset of bigVal1 into ESI
mov edi, OFFSET bigVal2 ; Load offset of bigVal2 into EDI
mov ebx, OFFSET result1 ; Load offset of result1 into EBX
mov ecx, 0 ; Set operation selector to 0(addition)
call subOperation ; Call subprogram
; Display result
mov esi, OFFSET result1
mov ecx, 14
call DumpMem
call DumpRegs
; Call the subprogram to perform subtraction
mov esi, OFFSET bigVal3 ; Load offset of bigVal3 into ESI
mov edi, OFFSET bigVal4 ; Load offset of bigVal4 into EDI
mov ebx, OFFSET result2 ; Load offset of result2 into EBX
mov ecx, 1 ; Set operation selector to 1(subtraction)
call subOperation ; Call subprogram
; Display result
mov esi, OFFSET result2
mov ecx, 14
call DumpMem
call DumpRegs
main ENDP
subOperation PROC
pushad ; Save all general-purpose registers
mov edx, 0 ; Clear EDX for carry/borrow
mov ecx, 14 ; Set counter for 14 bytes
performLoop:
mov al,[esi] ; Load byte from first operand
mov bl,[edi] ; Load byte from second operand
cmp ecx, 0
jne checkOperation
; Perform addition with carry
add al, bl
add dl,0
jmp storeResult
checkOperation:
cmp ecx, 1
je subBytes
; Perform addition with carry
add al, bl
add dl,0
jmp storeResult
subBytes:
; Perform subtraction with borrow
sub al, bl
sub dl,0
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 14 bytes
popad ; Restore all general-purpose registers
ret
subOperation ENDP
END main
main ENDP
Modify this based off this question: It is important to keep in mind that on Intel microprocessor-based systems,
multi-byte numbers are stored in memory least significant byte first(at the lowest-
numbered memory address), a.k.a.little-endian 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 little-endian 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 112-bit unsigned integers (each number is 14 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):
1. A CPU register must be used to pass the memory offset of the first operand to the
subprogram.
2. A second register must be used to pass the offset of the second operand to the
subprogram.
3. 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).
4. 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 0, 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: bigVal1+ bigVal2,
and a second time to subtract: bigVal3 bigVal4
bigVal1=9c073207b73c33ba9d563d6ded29
bigVal2=3d0e74c43ac1caeca755ae54ffa2
bigVal3= c1e4b53eace3844d23effa7a9531
bigVal4=5aa003c57dc56f2aafbd1713

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!