.cseg .org 0;Initialization code; Do not move or change these instructions or th
ID: 3844586 • Letter: #
Question
.cseg .org 0;Initialization code; Do not move or change these instructions or the registers they refer to.; You may change the data values being loaded.; The default values set A = 0x3412 and B = 0x0003 ldi r16, 0x12; Low byte of operand A ldi 17, 0x34 High byte of operand A ldi r18, 0x03; Low byte of operand B ldi r19, 0x00 High byte of operand B;Your task: Perform the integer division operation A/B and store the result in data memory.; Store the 2 byte quotient in DIV1: DIV0 and store the 2 byte remainder in MOD 1: MOD0.; ...Your code here ...;End of program (do not change the next two lines) stop; rjmp stop;Do not move or modify any code below this line You may add extra variables if needed.; The .dseg directive indicates that the following directives should apply to data memory .dseg .org 0x200;Star assembling at address 0x200 of data memory (addresses less than 0x200 refer to registers and ports) DIV0: byte 1; Bits 7...0 of the quotient DIV1: .byte 1 Bits 15...8 of the quotient MOD0: byte 1; Bits 7. .0 of the remainder MOD1: byte 1; Bits 15... 8 of the remainderExplanation / Answer
I have created and developed the Assembly program which calculates the 32 bit divison operation A / B. I have included the comments for each part of code and attached the final output of it.
Let me explain you in simpler and in step-by-step manner:-
Step-1:
The initial part is to initialize the code by using the include classes which helps to keep and store the data in the structure way.
Example:-
.cseg
.org 0
HighByte struc
LowByte dd ?
WordLow dd ?
HighByte ends
Step-2:
The next step is to set the data attribute into the values of A and B with their desired input values like,
Example:-
.data
A db "0x3412
B db "0x2010
Step-3:
The final step is to start the code with the moving of an variables for assigning the registers to their respective attributes and their specific location.
Example:-
.code
start:
mov eax, 0x3412
mov ecx, 0x3412
div ecx
Assembly Program:-
; Declared the data segment at the starting point
.cseg
.org 0
HighByte struc
LowByte dd ?
WordLow dd ?
HighByte ends
; Uses two variables with A and B
.data
A db "0x3412 = %llu",11, 8, 0
B db "0x2010 * 27020 = %llu",11, 8, 0
.data?
Bytes dq ?
HighByteNumberVal HighByte <>
; The code starts over here with mul operation
.code
start:
mov eax, 0x3412
mov ecx, 0x3412
div ecx
mov dword ptr[Bytes], eax
mov dword ptr[Bytes + 4], edx
invoke crt_printf, offset A, Bytes
mov eax, 0x2010
mov ecx, 520070
div ecx
mov HighByteNumberVal.LowByte, eax
mov HighByteNumberVal.WordLow, edx
invoke crt_printf, offset B, HighByteNumberVal
inkey
invoke ExitProcess, 0
end start
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.