Pl CORRIG 1.DOC
Jump to navigation
Jump to search
------------------------- EXERCISES PART I CORRECTIONS ------------------------- - The solutions to the exercises proposed in this file are related to exercises nr°1 in the file: EXOS_1.DOC ----------- Refer to the nr° of the exercise whose solution you want to know. ------------------ nr° 1: ------ The error in this program had to be found: text ab move.b #345,d0 ; -128<BYTE<128 !! add.b #1,d0 jmp ab end The answer was very simple, the error is in the first instruction, indeed, we do a 'MOVE.B #345,d0' i.e., we put Byte 345 in the low weight Byte of register d0, but I remind you that the maximum value a byte can have is 128 and 345>128, this leads to an error during assembly. To correct, simply write 'MOVE.W #345,d0' or 'MOVE.L #345,d0' nr° 2: ------ The value of data register d3 after the program had to be found. text move.l #12,d3 ;We put the L-M=12 in the d3 register add.l #4,d3 ;We add the L-M=4 to it: d3=12+4=16 add.l d3,d3 ;We add the L-M d3 to itself, so ;d3=d3+d3=16+16=32 (on an L-M) move.l var,d2 ;We put the L-M pointed by 'var', i.e. ;458 in the data register d2 add.l d2,d3 ;we add the L-M of d2 to the L-M of d3, ;so d3=d2+d3=458+32=490 (L-M) data ;data segment var dc.l 458 end As the Remarks show, d3=490 nr° 3: ------ It was asked what the d5 register would contain after the program. text move ici,d4 ;we place the word pointed by 'here' in the low ;weight word of the data register d4 ;so d4=10 (on a word) add #5,d4 ;we add the word 5 to the low weight word of d4 move d4,la ;We put the low weight word of d4 (15) at 'there' add ici,la ;We add the value pointed by 'here' to the ;data pointed by 'there', 'there' therefore points to ;a word (ds.w) equal to 10+15=25 move la,d5 ;We put the word pointed by 'there' in the low ;weight word of d5.So d5=25 data here dc.w 10 bss there ds.w 1 end We then find d5=25 nr°4: ----- You had to: Find the value of a4 at the end of the program knowing that the label 'ad' is located at an address equal to $ff0 and it points (dc.l) at the number 45 text move.l #ad,a4 ;we put the address of 'ad' (L-M) in the ;address register a4, so a4=$ff0 move.l ad,d5 ;we put the L-M pointed by 'ad', i.e. 45 in ;the data register d5 data ad dc.l 45 ;we suppose that here PC=$ff0 end In this specific case, a4=$ff0 (and not 45, review your lessons!) It was really very simple. nr°5: ----- You must find the value of d5 and a5 after this program. text move #15,d5 ;We put the word 15 in the low weight word of d5 move.l #zz,a5 ;We put the address of 'zz' in the address ;register a5 move zz,d5 ;We put the word pointed by 'zz' in the low ;weight word of the data register d5, so d5=0. data zz dc.w 0 end So d5=0 (word) and a5=address of 'zz' (L-M) nr°6: ----- The value contained at the address 'out', the value of d0 and d5 at the end of this program had to be found. text move #247,d0 ;we put the word 247 in the low weight word of d0 move #3,d5 ;we put the word 3 in the low weight word of d5 bbb add #8,d0 ;we add the word 8 to the low weight word of d0 move d0,out ;then we put the low weight word of d0 in 'out' dbf d5,bbb ;we come back to 'bbb' until d5=-1 ;i.e. 4 times because d5=3 at the beginning ;at the end of the loop, d0=247+(8*4)=279 (word) bss out ds.b 2 ;we reserve 2 Bytes (i.e. 1 word) in 'out' end In 'out' we therefore find a Word, the last value of d0 so 279, d5=-1 because its register is decremented until d5=-1. nr°7: ----- It was necessary to: Find the BINARY value of the data register d1 at the end of this program. knowing that 5438=%0001010100111110 text move #5391,d0 ;we put the word 5391 in the low weight word of d0 add #47,d0 ;we add 47, so d0=5438 (word) move d0,ten ;we put the low weight word of d0 in 'ten', ;as in 'ten' there is 'ds.b', only the high byte ;of d0 will be in 'ten', the low weight byte ;will be in 'in' (address 'ten'+1). move.b in,d1 ;we put the byte pointed by 'in' in the low weight ;byte of d1 ;in 'in' there is the low weight byte of d0, ;so d1 will contain %00111110 bss ten ds.b 1 ;reserve one byte in 'ten' in ds.w 47 ;reserve 47 words in 'in'='ten'+1 data null dc.w 5438 ;nothing to do here... end We therefore have d1=%00111110 (byte) nr°8: ----- What is going to happen in 'gag'? text move.l #gag,a2 ;a2 points to the address of 'gag' gag move.b #100,d1 ;we put the byte 100 in the low weight ;of d1 jmp (a2) ;we jump to the address pointed by a2 (so ;the address of 'gag') end The program is therefore an infinite loop, we put the byte 100 in d1 an infinite number of times. nr°9: ----- What will the value of d3 be after this program? text move.b #12,lab ;we put the byte 12 in 'lab' move.b #14,lac ;" " " " the byte 14 in 'lac' move.b #15,lad ;" " " " the byte 15 in 'lad' move.l #lab,a3 ;we put the address of 'lab' in a3 move.b #1,d1 ;we put the byte 1 in the low weight byte of a1 fff move.b (a3)+,d3 ;we take the value pointed by a3, we increment ;a3 by 1 (.b) and we put it in the low weight byte ;of d3. dbf d1,fff ;we decrement d1 by 1 unit until d1=-1 ;if d1 is different from -1, we jump to 'fff' add.b (a3),-(a3);we add the byte pointed by a3 (we decrement ;a3 by 1 (.b)) to the byte pointed by the new ;address of a3. move.b -(a3),d3 ;We decrement a3 by 1 (.b) and we put the value ;thus pointed in the low weight byte of d3 add.b (a3),d3 ;We add the value pointed by a3 to d3 (byte) bss lab ds.w 1 ;we reserve 1 L-M lac ds.b 1 ;we " 1 byte lad ds.w 5 ;we reserve 5 words end In 'fff', the first time: d1=1, a3 points to 'lab'. With 'move.b (a3)+,d3', we take the byte in 'lab', we increment a3 by one unit (.b) so now a3 points at 'lab'+1 and we put the byte in the low weight byte of d3, so d3=12 (we have put the byte 12 in 'lab'). Then we have: 'dbf d1,fff': d1=d1-1=0 as 0 is different from -1, we jump to 'fff'. again: 'move.b (a3)+,d3': we take the byte pointed by a3 (here a3 points to the second byte of 'lab', which is 0 since here nothing has been initialized...)and we put it in d3 after having incremented a3 by one unit: d3=0 and a3 points on 'lab'+2='lac'. We arrive at 'dbf d1,fff',again, d1=d1-1=-1, this time we will no more go to 'fff' because d1=-1: we continue. Then comes 'add.b (a3),-(a3)', a3 points to 'lac' ('lab'+2), we take the data (the byte) pointed by a3 (which is worth 14), we decrement a3 by one unit (.b) and we add it to the new value thus pointed by a3 (which is 0) finally: With 'move.b -(a3),d3' , we decrement a3 by one unit (so a3 points at 'lab') and we put the data thus pointed in the low weight byte of d3, so d3=12. Finally, with 'add.b (a3),d3', we add to d3 the data pointed by a3, as a3 points at 'lab', we get: d3=d3+12=12+12=24 Finally: d3=24. and a3 points at 'lab' ... nr°10: ------ What will be the values of d0, d1, d2, d3, a0 after this program? Easy... text move.b #10,a ;we put the byte 10 in a move.b #11,b ; 11 in b move.b #12,c ; 12 in c move.b #13,d ; 13 in d move.b #98,e ; 98 in e move.l #begin,a0 ;we put the address of 'begin' in a0 ;:a0 points to 'begin' move.b (a0)+,d0 ;we put the byte pointed by a0 :0 because nothing is ;initialized in 'begin',(we increment a0 by one ;unit (.b)), in d0, so: ;d0=0 (byte), a0=a0+1, so a0 points at 'a'. move.b (a0)+,d1 ;same for d1: d1=10, a0 points at 'a'+1='b' move.b (a0)+,d2 ;for d2: d2=11, a0 points at 'b'+1='c' move.b (a0),d3 ;We place the byte pointed by a0 in d3: ;a0 points at 'c', therefore d3=12 move.b -(a0),d4 ;decrement a0 by one unit and put the byte ;thus pointed by a0 in the low weight byte ; of d4: ;as a0 was pointing to 'c', we have now: ;a0='c'-1='b', so d4=11 (we have put 11 in 'b') bss begin ds.b 1 ;reserve 1 byte in begin a ds.b 1 ;in a b ds.b 1 ;in b c ds.b 1 ;in c d ds.b 1 ;in d e ds.b 1 ;in e f ds.l 4 ;reserve in L-M in f end So: d0=0, d1=10, d2=11, d3=12, d4=11, a0 points at 'b'. nr°11: ------ One had to find the value of a4 and d0, d1 after this program. text move.b #3,d0 ;we put the byte 3 in the register d0 move.l #stack,a4 ;we put the address of 'stack' in a4 rrr move.b -(a4),d1 ;we decrement a4 by one unit (.b) and put the ;byte pointed by a4 in the low weight byte of d1 add.b #4,d1 ;we add the byte 4 to the low weight byte of d1 dbf d0,rrr ;loop until d0=-1 data dc.b 1,2,3,4,5,6,7,8,9 ;9 bytes are stored here stack dc.b 245 ;byte 245 at the address 'stack' end at the end of the program, d0=-1, it is the loop counter... the loop: 1st pass: d0=3, a4 points to 'stack' with 'move.b -(a4),d1', we decrement a4 by 1 unit (because .b), we take the byte pointed by a4 and we place it in the low weight byte of d1: a4='stack'-1 so a4 is pointing to the byte '9', d1=9+4=13 because we 'add.b #4, d1' We decrement d0 and go back to 'rrr' because d0=2 2nd pass: d0=2, a4 points to the byte '9' The same operation as before: a4 is pointing to the byte '8', d1=8+4=12 (byte), d0=2-1=1 3rd pass: d0=1, a4 points to the byte '8' the same, we obtain: a4 is pointing to the byte '7', d1=7+4=11 (byte), d0=1-1=0 4th pass: d0=0, a4 points to the byte '7' the same, we have: a4 is pointing to the byte '6', d1=6+4=10 (byte), d0=0-1=-1 so we get out of the loop and finally: d0=-1, d1=10, a4 points to the byte '6' nr°12: ------ Let's find what is in 'out' and the value of d2. text a equ 3 ;we assign 3 to 'a' b equ 5 ; 5 to 'b' move.b a,d2 ;we put the byte pointed by 'a' in the low weight ;of d2, so d2=3 add.b b,d2 ;we add the byte pointed by 'b', so ;d2=d2+5=8 (byte) move.l #g,a5 ;we put the address of 'g' in a5 move.b d2,(a5) ;we put the low weight byte of d2 at ;the address pointed by a5 (so in 'g') move.b d2,-(a5) ;we put the low weight byte of d2 (we decrement ;a5 by one unit) at the new address of a5 ;(here, a5 points to 'out', so we will find d2 ;i.e. the byte 8 in 'out') move.b (a5)+,d2 ;we put the byte pointed by a5 (so the byte 8) ;(we increment a5 by 1 unit) in the low weight byte ;of d2: d2=8 and a5 points to 'g' move.b (a5),d2 ;we put the byte pointed by a5 in the low weight ;of d2: a5 points to 'g', in 'g' there is ;the byte 8 so d2=8 once again. bss out ds.b 1 g ds.b 4 end conclusion: in 'out' there is the byte 8 and d2=8 (byte) nr°13: ------ We need to find the value of d1, d2, d3, d4, and a0. text move.l #out,a0 ; we place the address of 'out' in a0 move.w #2,d3 ; we place the word '2' in d3 move.w (a0),d1 ; we place the word pointed by a0 (which is 15) into ; the low word of d1: d1=15 (a0='out') move.w -4(a0),d2 ; we take the word pointed by a0-4 (mode d(an)) ; and place it in the low word of d2: d2=12 (a0='out') move.w -4(a0,d3),d3 ; we take the word pointed by 'a0'+d3-4 ; (mode d(an,rn)) which is 'a0'-2 and place it ; in the low word of d3: d3=2356 (a0='out') move.w -(a0),d4 ; we decrement a0 by 2 units (.w) so a0 ; now points to 2356 and we place this ; word in the low word of d4: ; d4=2356 and a0 points to the word 2356 data dc.l 1 dc.w 12 dc.w 2356 out dc.b 15 end Conclusion: d1=15, d2=12, d3=2356, d4=2356, and a0 points to the word 2356 nr°14: ------ We were asked: What are the different values taken by a0 during this program? What is the final value contained in 'res'? text move.l #a,a5 ; we place the address of 'a' in a5 move.l #2,d2 ; we place the L-M '2' in d2 ttt move.b #1,(a5)+ ; we add the byte 1 to the address pointed by a5 ; then increment a5 by one unit (.b) dbf d2,ttt ; loop move.b #5,(a5) ; we place the byte 5 at the address pointed by a5 move.l #vec,a1 ; we place the address of 'vec' in a1 move.b #3,d0 ; we place the byte 3 in the low byte ; of d0 move.b #0,d2 ; we place the byte 0 in the low byte ; of d2 cde move.l 0(a1,d2),a0 ; we place the L-M pointed by 'a1'+d2 in a0 add.l #4,d2 ; we add the L-M 4 to d2 move.b (a0),res ; we place the byte pointed by a0 in 'res' dbf d0,cde ; loop data vec dc.l a,b,c,d ; 4 L-M containing the addresses of 'a','b' ; ,'c','d' bss a ds.b 1 ; here we reserve the bytes b ds.b 1 c ds.b 1 d ds.b 1 res ds.b 1 end 1st loop: in ttt --------- 1st pass: d2=2, a5 points to 'a' ---------- We place the byte '1' in 'a' then increment a5 by one unit, a5 now points to 'b' and we go back to 'ttt' after decrementing d2 2nd pass: d2=1, a5 points to 'b' ---------- We place the byte '1' in 'b' then increment a5 by one unit, a5 now points to 'c' and we go back to 'ttt' after decrementing d2 3rd pass: d2=0, a5 points to 'c' ---------- We place the byte '1' in 'c' then increment a5 by one unit, a5 now points to 'd', then with 'dbf', we decrement d2 which now equals -1, i.e., we exit the loop. With 'move.b #5,(a5)', we place the byte '5' at the address pointed by a5, which is 'd' At the end of this loop, we find the byte '1' in 'a', 'b', 'c' and the byte '5' in 'd' Then comes the 2nd loop in 'cde': --------- 1st pass: d2=0, d0=3, a1 points to 'vec' ----------- We place the L-M pointed by 0+'vec'+d2 i.e., 'vec'+0 in a0: a0 thus equals 'a', then we add '4' to d2, we place the byte pointed by a0 (in 'a') in 'res' with 'move.b (a0),res'. In 'a' there is the byte '1', so this means placing the byte '1' in res. With 'dbf d0,cde', we decrement d0 and return to 'cde' 2nd pass: d2=4, d0=2, a1 points to 'vec', a0 points to 'a' ---------- We place the L-M pointed by 0+'vec'+d2 i.e., 'vec'+4 in a0: a0 thus equals 'b', then we add '4' to d2, we place the byte pointed by a0 (in 'b') in 'res' with 'move.b (a0),res'. In 'b' there is the byte '1', so this means placing the byte '1' in res. With 'dbf d0,cde', we decrement d0 and return to 'cde' 3rd pass: d2=8, d0=1, a1 points to 'vec', a0 points to 'b' ---------- We place the L-M pointed by 0+'vec'+d2 i.e., 'vec'+8 in a0: a0 thus equals 'c', then we add '4' to d2, we place the byte pointed by a0 (in 'c') in 'res' with 'move.b (a0),res'. In 'c' there is the byte '1', so this means placing the byte '1' in res. With 'dbf d0,cde', we decrement d0 and return to 'cde' 4th pass: d2=12, d0=0, a1 points to 'vec', a0 points to 'c' ---------- We place the L-M pointed by 0+'vec'+d2 i.e., 'vec'+8 in a0: a0 thus equals 'd', then we add '4' to d2, we place the byte pointed by a0 (in 'd') in 'res' with 'move.b (a0),res'. In 'd' there is the byte '5', so this means placing the byte '5' in res. With 'dbf d0,cde', we decrement d0: d0=-1, we exit the loop. In 'res' we find the byte '5'. At the end: a0='d' nr°15: ------ We need to find the value pointed by ret, at the end of this program. text move.l #5,a ; we place the L-M 5 in 'a' move.l #a,a0 ; we place the address of 'a' in a0 move.l (a0)+,d2 ; we place the L-M pointed by a0 (which is 5) (we increment ; a0 by 4 units) in d2 move.l d2,ret ; we place the L-M contained in d2 in 'ret' bss a ds.l 2 ; we reserve 2 L-M in 'a' ret ds.l 1 ; we reserve one L-M in 'ret' end We find the L-M '5' at the address 'ret'. n°16: ----- Find the value of d0 and a0 after this program. text move.b #3,d1 ;place the byte 3 in the least significant ;byte of d1 move.b #a,a0 ;place the address of 'a' in a0 mno move.b 1(a0,d1),d0 ;place the byte pointed by 1+'a0'+d1 in ;the least significant byte of d0 add.b #14,d0 ;add the byte 14 to the least significant ;byte of d0 add.b a,d0 ;add the byte pointed by 'a', which is 0 ;to the least significant byte of d0 dbf d1,mno ;loop (4 times) data a dc.b 0,5,6,7,8,9 end 1st pass in the mno loop: d1=3, a0 points to 'a', d0=0 ---------- Place the byte pointed by 1+'a'+d1, which is 'a'+4 (thus the byte '8') in d0. Add the byte 14 and the byte 0: d0=8+14+0=22 Then decrement d1, the loop counter, and return to 'mno' 2nd pass: d1=2, a0 points to 'a', d0=22 ---------- Place the byte pointed by 1+'a'+d1, which is 'a'+3 (thus the byte '7') in d0. Add the byte 14 and the byte 0: d0=7+14+0=21 Then decrement d1, the loop counter, and return to 'mno' 3rd pass: d1=1, a0 points to 'a', d0=21 ---------- Place the byte pointed by 1+'a'+d1, which is 'a'+2 (thus the byte '6') in d0. Add the byte 14 and the byte 0: d0=6+14+0=20 Then decrement d1, the loop counter, and return to 'mno' 4th pass: d1=0, a0 points to 'a', d0=20 ---------- Place the byte pointed by 1+'a'+d1, which is 'a'+1 (thus the byte '5') in d0. Add the byte 14 and the byte 0: d0=5+14+0=19 Then decrement d1, the loop counter, d1=-1, exit the loop Finally: d0=19 and a0 points to the address of 'a' nr°17: ------ Find the value of d3 after this program. text move.l #a,a0 ;place the address of 'a' in a0 move.b #5,(a0)+ ;place the byte 5 at the address pointed by ;a0 and increment a0 by one unit ;thus placing byte 5 in 'a' move.b #6,(a0)+ ;place the byte 6 at the address pointed by ;a0 and increment a0 by one unit ;thus placing byte 6 in 'a'+1 move.b -(a0),d2 ;decrement a0 by one unit and place ;the byte pointed by a0 in the least significant ;byte of d2 ;thus placing the byte from 'a'+1+1-1, which is ;'a'+1 or byte 6 in d3 move.l #a,a0 ;place the address of 'a' in a0 move.b 1(a0),d3 ;place the byte at 'a'+1 in the least significant ;byte of d3 ;which is byte 6 in d3 add.b d2,d3 ;add the 2 bytes of d2 and d3, the ;result is in d3: d3=6+6=12 bss a ds.w 1 ;reserve 1 word in 'a' ds.b 1 ;reserve 1 byte in 'a'+2 end So, d3=12 nr°18: ------ Find what happens in 'stp', and what is contained in 'res'? text move.w #5,d3 ;place the word 5 in the least significant ;word of d3 add.b #6,d2 ;add the byte 6 to the least significant ;byte of d2, so d2=0+6=6 add.b d2,d3 ;add the least significant bytes of d2 and ;d3, the result is in d3: d3=11 move.l #ad,a0 ;place the address of 'ad' in a0 stp jmp 10(a0) ;jump to the address a0+10 (d(an) mode) which is ;'ad'+10 ad move.l #5,res ;at 'ad', there is an instruction of a size ;of 10 bytes (4 for '.l', +4 for the word '5', ;+2 for extension words=10 bytes) move.b d3,res ;thus jump here and place the least significant ;byte of d3 in 'res' bss res ds.b 1 end In 'stp', the program jumps over the instruction at 'ad' and in 'res', we find the byte 11 nr°19: ------ Now the quick response questions: a) If I write 'MOVE.W #0,d0', what will happen to the CCR? And if I then write 'ADD.W #-2,d0'? With 'move.w #0,d0', place the word 0 in the least significant word of d0, this will set the 'Z' (Zero) bit of the CCR to 1. With 'add.w #-2,d0', place the word -2 in the least significant word of d0, this will set the 'N' (Negative) bit of the CCR to 1. b) Can we place a BYTE at an odd address? Yes! It's also possible with a Bit, but not with a Word or a Long Word (see the course...) c) How many digits are used to code a L-M in HEXADECIMAL? By 8 Hex digits. (see the course) d) Can we use the PC to store a digit like with a data or address register? (I remind you that it's a register). If yes, how? FALSE!! The PC is indeed a register, but it's impossible to place a data in it. The PC is only changed by jump instructions and each time an instruction is executed. e) The 'END' directive ends the program and allows return to the DESKTOP, True or False? Argue. FALSE!! It only indicates to the assembler that the listing is finished. To return to the DESKTOP (or GEM Desktop) you need to use a GEMDOS instruction (we will see how in detail) f) A macro instruction is a subroutine called by the Linker each time its name is encountered in the object code. True or False? Explain. FALSE!! Review the course, everything is explained in detail... g) Any addressing mode can be used for the operands of the 68000 instructions. True or False? FALSE!! Instructions only accept certain addressing modes for their source and destination operands. Therefore, I will need to indicate for each instruction the different addressing modes accepted for the operands. For example: Move (an)+,d(pc,rn) will be impossible... We will see all this in detail when I comment on the different instructions of the 68000. ----------------- PIECHOCKI Laurent 8,impasse Bellevue 57980 TENTELING
Back to ASM_Tutorial