-------------------------
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 must find the value of d1, d2, d3, d4 and a0.