Considering the MAIN (incomplete code segment) below, complete the MAIN code seg
ID: 3563409 • Letter: C
Question
Considering the MAIN (incomplete code segment) below, complete the MAIN code segment and write 68000/IDE68K ISR's to handle 'Address error' and Divide by zero' exceptions as explained below. Write adequate comments.
(i) If 'Address error' happens, write 0x8 (00001000) to $B00
(ii) If 'Divide by zero' happens, write 0x20 (00100000) to $B00
(iii) If both 'Address error' & 'Divide by zero' happen, write 0x28 (00101000) to $B00
MAIN ORG $400
MOVE.B .....
.....
.....
MOVE.W $A01,D1 ;D0 (16-0) contains a word value from $A01
MOVEQ #0,D1 ;D1 = 0
DIVU.W D1,D0 ;D0(32)/D1(16) ? D0(16R:16Q)
MOVE.L $A01,D0 ;D0(31-0) HOLDS WORD VALUE FROM $A01
DIVU.W D1,D0 ;D0(32)/D1(16) ? D0(16R:16Q)
BRA DONE ;done
So basically the given code will cause the address error & divide by zero error. I need to finish the code to do i, ii, and iii. I think the code needs to chech which error happened in exception handler and then see if the other one has happened yet.....using flags I think. I'm honestly not sure how to do this though so I would appreciate some help! Also please add comments and I will give points to the best answer!!!
Explanation / Answer
MAIN ORG $400
MOVE.l #addrerr,0x0C ; Vector location of addrerror is 0x0C
MOVE.l #divzerotrap,0x14 ; vector location of divide by 0 trap is 0x14
MOVE.W $A01,D1 ;D0 (16-0) contains a word value from $A01
MOVEQ #0,D1 ;D1 = 0=
DIVU.W D1,D0 ;D0(32)/D1(16) ? D0(16R:16Q)
MOVE.L $A01,D0 ;D0(31-0) HOLDS WORD VALUE FROM $A01
DIVU.W D1,D0 ;D0(32)/D1(16) ? D0(16R:16Q)
DONE BRA DONE ;done
addrerr move.b $B00,D0 ;read the current value at location $B00
ori #0x08,D0 ;or the contents with 0x08 for addr error
move.b D0,$B00 ; store the value at $B00
rte
divzerotrap move.b $B00,D0;read the current value at location $B00
ori #0x20,D0 ; or the contents with ox20 for div with 0 trap
move.b D0,$B00 ; store the value at $B00
rte