Question: AVR language code. Let A and B be 16-bit unsigned integers. The product AB requires at most 32 bits. The quotient A/B and remainder A%B
AVR language code. Let A and B be 16-bit unsigned integers. The product AB requires at most 32 bits. The quotient A/B and remainder A%B each require at most 16 bits.
Modify the code below to compute the product AB and store it in memory as a 32-bit little-endian unsigned integer.
;mul32.asm
.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 = 0x2010
ldi r16, 0x12 ; Low byte of operand A
ldi r17, 0x34 ; High byte of operand A
ldi r18, 0x10 ; Low byte of operand B
ldi r19, 0x20 ; High byte of operand B
; Your task: compute the 32-bit product A*B (using the bytes from registers r16 - r19 above as the values of
; A and B) and store the result in the locations OUT3:OUT0 in data memory (see below).
; You are encouraged to use a simple loop with repeated addition, not the MUL instructions, although you are
; welcome to use MUL instructions if you want a challenge.
; ... 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 ; Start assembling at address 0x200 of data memory (addresses less than 0x200 refer to registers and ports)
OUT0: .byte 1 ; Bits 7...0 of the output value
OUT1: .byte 1 ; Bits 15...8 of the output value
OUT2: .byte 1 ; Bits 23...16 of the output value
OUT3: .byte 1 ; Bits 31...24 of the output value
Here is a photo for reference
mul 32.asm Cse0 org o :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 ?= 0x3412 and B 0x2010 ldi rl6, 0x12 Low byte of operand A ldi rl7, 0x34 High byte of operand A ldi r18, 0x10 Low byte of operand B ldi rl9, 0x20 High byte of operand B : Your task: compute the 32-bit product A B (using the bytes from registers rl6rl9 above as the values of :A and B) and store the result in the locations OUT3:OUTO in data memory (see below) ; You are encouraged to use a imple loop with repeated addition, not the MUL in?tructions, although you are : welcome to use MUL instructions if you want a challenge Marks Com nu132.asn correct Note that to be "correct", the result must be stored in the required memory locations OUT3:OUTO) Solutions which store the result anywher else (or leave it in registers) will not receive any marks :... Your code here u132.as code gives the correct result when the product is at most : End of program (do not change the next two lines) The mul32.asm code gives the correct result when one operand is less than 256 ( stop: the other is unonstrained) jp stop u132.asm gives the correct operand pairs. ; Do not move or modify any code below th15 line. You may add extra variable ? if needed The dseg directive indicates that the following directives should apply to data memory .dseg org 0x200 Start assembling at address 0x200 of data memory (addresses less than 0x200 refer to registers and ports) OUTO .byte Bits 7...0 of the output value UTI OUT2. .byte 1 ; Bit ? 23. .. 16 of the output value OUT3: byce Bits 15.. .8 of the output value byte Bits 31.. .24 of the output value mul 32.asm Cse0 org o :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 ?= 0x3412 and B 0x2010 ldi rl6, 0x12 Low byte of operand A ldi rl7, 0x34 High byte of operand A ldi r18, 0x10 Low byte of operand B ldi rl9, 0x20 High byte of operand B : Your task: compute the 32-bit product A B (using the bytes from registers rl6rl9 above as the values of :A and B) and store the result in the locations OUT3:OUTO in data memory (see below) ; You are encouraged to use a imple loop with repeated addition, not the MUL in?tructions, although you are : welcome to use MUL instructions if you want a challenge Marks Com nu132.asn correct Note that to be "correct", the result must be stored in the required memory locations OUT3:OUTO) Solutions which store the result anywher else (or leave it in registers) will not receive any marks :... Your code here u132.as code gives the correct result when the product is at most : End of program (do not change the next two lines) The mul32.asm code gives the correct result when one operand is less than 256 ( stop: the other is unonstrained) jp stop u132.asm gives the correct operand pairs. ; Do not move or modify any code below th15 line. You may add extra variable ? if needed The dseg directive indicates that the following directives should apply to data memory .dseg org 0x200 Start assembling at address 0x200 of data memory (addresses less than 0x200 refer to registers and ports) OUTO .byte Bits 7...0 of the output value UTI OUT2. .byte 1 ; Bit ? 23. .. 16 of the output value OUT3: byce Bits 15.. .8 of the output value byte Bits 31.. .24 of the output value
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
