Title: Addressing Instructions
1Addressing Instructions
- In fact there is no such instruction as
- move 4100,a0
- An assembler will usually accept it and convert
it to the correct form prior to assembling - movea 4100,a0
- Note
- Apart from cmpa, the address register forms do
not affect the CCR.
2cmpa Instruction
Now the code can be re-written using the cmpa
instruction
move.l 2000,a0 addr 2000 while cmpa.l
2100,a0 WHILE addr ove.b 1,(a0) (addr) 1 add.l 1,a0
addr addr 1 bra while
endwhile trap 0
3Immediate Compare
- There is another form of the cmp instruction
- cmpi Value,
- No longer restricted to using a data register as
the destination
4Example
cmpi ff,2000 cmpi 1,d0 cmpi
2100,a0 As with the cmp/cmpa instruction, some
assemblers will choose either cmp or cmpi based
on the operands that follow.
5But
It is better to use the appropriate form
(faster). Never completely trust the
assembler/compiler.
6Example Program
Determine the address in memory of the last SPACE
character in the string located at 2000 and
store this address in 2100. String Sequence
(list) of character usually stored sequentially
in memory as ASCII data (bytes).
7Example
The string is 1ba3 is fun. The 00 (the NULL
character) at the end is an EOS (End Of String)
marker which is required if the length of the
string is not known.
8DeMons dm (Display Memory)
If stored at 2000 then the dm command will
reveal the following
To check for the last space. We will look for
character code 20 ASCII code for a space.
9English Solution
Scan through the string a character at the time.
Whenever we see a space character, store the
current address. Continue until the end of the
string has been reached, and store the last
address in 2100.
10Pseudo-code
We require the use of pointer - Address
Register Use a WHILE or DO_WHILE loop? Is there a
possibility of 0 or more iterations or will we
loop at least once? If first character NULL
character then no space were found and the loop
shouldnt be executed (i.e. 0 times)
11Pseudo-code
- Use a WHILE loop
Note that SpaceP has been assigned the value of 0
initially in case the first character in the
string is 00 (in other words the string is a
NULL-STRING).
SpaceP 0 CurrP 2000 while ((CurrP) ! 0)
if ((CurrP) SPACE) SpaceP
CurrP CurrP CurrP 1 (2100) SpaceP
12Convert to Assembly Language
Variable Assignment CurrP - a0 Space - a1 To
determine whether the current character is a
space we would use cmpi.b 20,(a0) Remember
The ASCII number spacification Decimal Hex ASCI
I 61 97 a 32 20 - Compare
instruction can be written as cmpi.b ,(a0)
13Now we can write the code
movea.l 0,a1 SpaceP 0 movea.l 2000,a0
CurrP 2000 while cmpi.b 0,(a0)
WHILE CurrP 0 beq endwhile cmpi.b
,(a0) If (CurrP) bne endif
movea.l a0,a1 SpaceP CurrP
endif adda.l 1,a0 CurrP CurrP
1 bra while endwhile move.l
a1,2100 Store the result trap 0