Modify the code below: Add code to display both sum and diff in a hexadecimal format on the screen, all bytes must be stored in a reversed sequence order. code: .386 ; Tells MASM to use Intel 80386 instruction set. .MODEL FLAT ; Flat memory model option casemap:none ; Treat labels as case-sensitive INCLUDE IO.H ; header file for input/output .STACK 100h ; (default is 1-kilobyte stack) .const ; Constant data segment .DATA ; Begin initialized data segment op1 QWORD 0A2B2A40675981234h ; first 64-bit operand for addition op2 QWORD 08010870001234502h ; second 64-bit operand for addition sum DWORD 3 dup(?) ; 96-bit sum = ????????????????????????h op3 DWORD 2h, 0h, 0h ; 96-bit operand to subtract: 20000000200000002h .CODE ; Begin code segment _main PROC ; Beginning of code ;----------------------------------------------------------------------------- ; add two 64 bit numbers and store the result as 96 bit sum ;----------------------------------------------------------------------------- mov EAX, DWORD PTR [op1] ; EAX = low bits of first 64 bit integer mov EBX, DWORD PTR [op1 + 4] ; EBX = high bits of first 64 bit integer mov ECX, DWORD PTR [op2] ; ECX = low bits of second 64 bit integer mov EDX, DWORD PTR [op2 + 4] ; EDX = High bits of second 64 bit integer add EAX, ECX ; EAX = EAX + ECX adds low bits of the two 64 bit integers adc EBX, EDX ; EBX = EBX + EDX + CF adds high bits of the two 64 bit integers mov DWORD PTR [sum], EAX ; store the low bits sum mov DWORD PTR [sum + 4], EBX ; store the high bits sum adc DWORD PTR [sum + 8], 0 ; adds sum + 8 + CF ;--------------------------------------------------------------------------------- ; subtract 96 bit op3 from the sum and store the result in sum ;-------------------------------------------------------------------------------- mov EAX, DWORD PTR [op3 + 0] ; EAX = low bits of 96 bit op3 sub DWORD PTR [sum + 0], EAX ; subtract the low bits mov EAX, DWORD PTR [op3 + 4] ; EAX = middle bits of 96 bit op3 sbb DWORD PTR [sum + 4], EAX ; subtract the middle bits and carry flag mov EAX, DWORD PTR [op3 + 8] ; EAX = high bits of 96 bit op3 sbb DWORD PTR [sum + 8], EAX ; subtract the high bits and carry flag ret _main ENDP
Modify the code below:
Add code to display both sum and diff in a hexadecimal format on the screen, all bytes must be stored in a reversed sequence order.
code:
.386 ; Tells MASM to use Intel 80386 instruction set.
.MODEL FLAT ; Flat memory model
option casemap:none ; Treat labels as case-sensitive
INCLUDE IO.H ; header file for input/output
.STACK 100h ; (default is 1-kilobyte stack)
.const ; Constant data segment
.DATA ; Begin initialized data segment
op1 QWORD 0A2B2A40675981234h ; first 64-bit operand for addition
op2 QWORD 08010870001234502h ; second 64-bit operand for addition
sum DWORD 3 dup(?) ; 96-bit sum = ????????????????????????h
op3 DWORD 2h, 0h, 0h ; 96-bit operand to subtract: 20000000200000002h
.CODE ; Begin code segment
_main PROC ; Beginning of code
;-----------------------------------------------------------------------------
; add two 64 bit numbers and store the result as 96 bit sum
;-----------------------------------------------------------------------------
mov EAX, DWORD PTR [op1] ; EAX = low bits of first 64 bit integer
mov EBX, DWORD PTR [op1 + 4] ; EBX = high bits of first 64 bit integer
mov ECX, DWORD PTR [op2] ; ECX = low bits of second 64 bit integer
mov EDX, DWORD PTR [op2 + 4] ; EDX = High bits of second 64 bit integer
add EAX, ECX ; EAX = EAX + ECX adds low bits of the two 64 bit integers
adc EBX, EDX ; EBX = EBX + EDX + CF adds high bits of the two 64 bit integers
mov DWORD PTR [sum], EAX ; store the low bits sum
mov DWORD PTR [sum + 4], EBX ; store the high bits sum
adc DWORD PTR [sum + 8], 0 ; adds sum + 8 + CF
;---------------------------------------------------------------------------------
; subtract 96 bit op3 from the sum and store the result in sum
;--------------------------------------------------------------------------------
mov EAX, DWORD PTR [op3 + 0] ; EAX = low bits of 96 bit op3
sub DWORD PTR [sum + 0], EAX ; subtract the low bits
mov EAX, DWORD PTR [op3 + 4] ; EAX = middle bits of 96 bit op3
sbb DWORD PTR [sum + 4], EAX ; subtract the middle bits and carry flag
mov EAX, DWORD PTR [op3 + 8] ; EAX = high bits of 96 bit op3
sbb DWORD PTR [sum + 8], EAX ; subtract the high bits and carry flag
ret
_main ENDP
END _main ; Marks the end of the module and sets the program entry point label
Trending now
This is a popular solution!
Step by step
Solved in 3 steps