









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










Lecture #
Lecture #
;Length of Table
Table
#Table CLRA L^
;Table(i)=Table(i)/
& increment pointer
INCA
; Increment counter
CPA LEN
; Done?
BLE^
;If not, do again
{Continue processing}
Lecture #
Turn a sequence of ASCII digits into a number^ Complete (small) Flowchart Example:^4
Begin
Digit? No
Yes
Digit? No
Yes Done
Lecture #
Repeat Until Looping
max_val
ā^ Array[N]ā^ i N- max_val < array[i]?
yes
no
max_val no
ā^ Array[i]
Lecture #
.lst file Generated
C:\Miniide\Untitled1.lst
by MGTEK Assembler ASM
V1.22 Build 137 for WIN
(x86) -
Tue Sep
11 08:55:19 20071:
=
N^
equ^
20
2:^
=
org^
$
3:^0800
max_val
ds.b
1
4:^ 0801 01
03 05 06
13 29
array
dc.b
1,3,5,6,19,41,53,28,13,42,76,
0807 35
1C 0D 2A
4C 0E
5:^ 080D 14
36 40 4A
1D 21
dc.b^
20,54,64,74,29,33,41,
0813 29
2D 6:^
=
org^
$
7:^ 1000 B
0801
ldaa^
array
; set array[0] as
the^
temporary max
val
8:^ 1003 7A
0800
staa^
max_val
;^
ā
9:^ 1006 CE
0814
ldx^
#array+N-
;^ start from the end
of the
array
10:^
1009 C
13
ldab^
#N-^
; set loop
count
to N
11:^
100B B
0800
loop^
ldaa^
max_val
12:^
100E A
00
cmpa^
0,x
13:^
1010 2C
05
bge^
chk_end
14:^
1012 A
00
ldaa^
0,x
15:^
1014 7A
0800
staa^
max_val
16:^
1017 09
chk_end
dex
17:^
1018 04
31 F
dbne^
b,loop
; finish
all the
comparison
yet?
18:^
101B 20
FE^
forever
bra^
forever
; Better
to use swi.
Why?
19:^
end
Symbols:array
chk_end
Forever
*0000101b Loop^
*0000100b max_val
N^
Lecture #
BRSET & BRCLR
-^ These instructions combine 1) a mask operation,2) a compare operation, and 3) a conditionalbranch operation.^ BRCLR
mem
mask
rel_addr
(mem) bits
that are 1 in the mask
are cleared
BRSET
mem
mask
rel_addr
(mem) bits
that are 1 in the mask
are set
Lecture #7 10
BRSET
Example
-^ Suppose Data is memory location $3000 andthe content of this location is $4B. We execute:^ BRSET
Data
%
Exit
Does the branch to
Exit
take place?
(Data) = $4B = 0100 10110100 1011 ⢠0110 0000 = 01
0 0 0000
ā ā ā ā ^
01^1
0 0000
Therefore branch is NOT taken.Give an example of (Data) for which branch willoccur.
Lecture #7 11
Use
BRCLR
in looping example
Example 2.
Write a program to compute the number of elements that are divisible by 4 in an array of N 8-bit elements. Use the
repeat S until C
looping construct.
Solution:
A number divisible by 4 would have the least significant two bits equal 0s. Use
to test both bits at the same time.^ N
equ^
org^
; Data Area
total
ds.b
array
dc.b
dc.b
org^
; Program area
clr^
total
; initialize total to 0
ldx^
#array ldab
; use B as the loop count
loop
brclr
0,x,%00000011,yes
; check bits 1 and 0
bra^
chkend
; No, donāt include in total
yes^
inc^
total
; Yes, include in total
chkend
inxdbne
b,loop
; Done?
If not loop back.
swi^
; Done.
end
Shift and Rotate Instructions
C^
b7 ------------------------ b
C
b7 ------------------------ b
C^
a7 ------------------------ a
b7 ------------------------ b
accumulator A
accumulator B
C
b7 ------------------------ b 0
C
0
a7 ------------------------- a
b7 ----------------------- b
accumulator A
accumulator B