## Review Assembly language

Instruction Set
1. arithmetic op
2. logical op
3. data transfer
4. control transfer
5. others

arithmetic op :        ADD, SUB, INC
logical op :              CMP, AND, OR
data transfer :         LDA, STA
control transfer :    BEQ, JMP, JSR
others :                    NOP

* absolute                   LD R1, 100
* indirect                     LD R1,(100)
* index                         LD  R1,(R2+R3)
* auto-increment        LD R1,(R2)+
* auto-decrement       LD R1,-(R2)

Case study of an assembly language    Motorola 6800
with the simulator  SIM68 and an assembler  A68

programmer model of 6800
A    8 bits
B    8 bits
X    16 bits index register
SP    16 bits   stack pointer
CC    8 bits    H,I,N,Z,V,C

memory model of 6800
64K :   00-FF for short,   0000-FFFF long

assembler a68
directive .ORG, .END, .DB  define byte, .DW define word
symbolic name   NAME:
literal    H'100 (hex), 100,  #2,  #'A'

Example   Find max from array AR[0..2]

max = ar[0]
i = 1
while i <= 2 do
if max < ar[i] then max = ar[i]
i = i + 1
;  Find max from array ar[0..2]
;
.org h'100
ldx i
ldaa ar,x
staa max     ; max = ar[0]
loop: ldaa i+1     ; use 8 bit of i
cmpa #2
bgt exit     ; while i <= N
ldaa ar,x
cmpa max     ; if max < ar[i]
ble skip
staa max     ; then max = ar[i]
skip: inx          ; i = i+1
stx i
jmp loop
exit:
.org h'10
max:  .db 0        ; max
i:    .dw 0        ; index must be 16 bit
ar:   .db 4,5,6    ; array
.end