Q1) Multiply R16, and R17 and send output on port A and Port B.
Write code in Assembly
Q2) Write assembly code to devide R17 value with R18 value.
solution:
values of base and high in two registers (R16 and R18). These are 8 bit values
.include "./m2560def.inc"
;
; Constants
;
.def base = r16
.def high = r17
.equ base_value = 10
.equ high_value = 20
.cseg
.org 0x0000
rjmp reset ; reset intr
reset:
LDI R16, HIGH(RAMEND)
OUT SPH, R16
LDI R16, LOW(RAMEND)
OUT SPL, R16
RCALL configure_ports
start:
LDI base, base_value
LDI high, high_value
MUL base, high
MOVW R18, R0
LSR R18 ;divide by 2
MOV R19, R18
OUT PORTB, R19 ;Output result in PORTB
OUT PORTD, R19 ;Output result in PORTD
RJMP start
configure_ports:
;Configurare B and C ports as outputs
LDI R16, 0XFF
OUT DDRB, R16
OUT DDRC, R16
ret
please give me thumb up
Get Answers For Free
Most questions answered within 1 hours.