Implement the following functions with AVR assembly language 1) 2-byte addition (i.e, addition on 16-bit numbers) 2) 2-byte signed subtraction 3) 2-byte signed multiplication
1) 2-byte addition Code
.DEF AL = R16 ;To hold low byte of value1 .DEF AH = R17 ;To hold high byte of value1 .DEF BL = R18 ;To hold low byte of value2 .DEF BH = R19 ;To hold high byte of value2 add: ADD AL,BL ;Add the lower bytes together ADC AH,BH ;Add the higher bytes and include carry bit BRCS OVERFLOW ret
2) 2 byte signed subtraction
subtract:
SUB AL,BL ;Subtract two low bytes SBC AH,BH ;Subtract two high bytes and include carry BRCS UNDERFLOW ret
3) 2 byte signed multiplication
mul16x16_16:
mul r22, r20 ; al *
bl
movw r17:r16, r1:r0
mul r23, r20 ; ah *
bl
add r17, r0
mul r21, r22 ; bh *
al
add r17, r0
ret
Get Answers For Free
Most questions answered within 1 hours.