Developing Software in Assembly Language
6812 Assembly Language Shift Examples
By Jonathan W. Valvano
This article, which discusses assembly language programming,
accompanies the book Embedded Microcomputer Systems: Real Time Interfacing published by Brooks-Cole 1999. This document has four overall
parts
Overview
Syntax (fields, pseudo ops)
Local variables
Examples
Shift Examples on the 6812
8-bit shift left
8-bit unsigned shift right
8-bit signed shift right
32-bit shift left
32-bit unsigned shift right
32-bit signed shift right
Other Examples
Arithmetic Examples on the 6812
Stack Usage and Interrupts on the 6812
Interpreters on the 6812
FIFO Queue Examples on the 6812
Control Structure Examples on the 6812
--------------------------------------------------------------------------------------
8-bit arithmetic left shift, unsigned or signed
org $0800
data rmb 1
org $F000
; make data=6*data (signed 8 bit)
; V=1 if overflow
Mul6 ldaa data
tab ;save a copy
asla ;times 2
bvs err
aba ;times 3
bvs err
asla ;times 6
err staa data
rts
org $0800
data rmb 1
org $F000
; make data=4*data (signed 8 bit)
; V=1 if overflow
Mul4 ldab data
aslb ;times 2
bvs err
aslb ;times 4
err stab data
rts
--------------------------------------------------------------------------------------
8-bit arithmetic right shift, signed
org $0800
data rmb 1
org $F000
; make data=data/4 (signed 8-bit)
Div4 asr data ; divide by 2
asr data ; divide by 4
rts
--------------------------------------------------------------------------------------
8-bit logic right shift, unsigned
org $0800
data rmb 1
org $F000
; make data=data/4 (unsigned 8-bit)
Div4 lsr data ; divide by 2
lsr data ; divide by 4
rts
--------------------------------------------------------------------------------------
32-bit shift left N=N<<1 (unsigned and signed) on the 6812
N ds 4 ; 32-bit number
asl32 asl N+3 ; start with least significant byte
rol N+2 ; next byte
rol N+1 ; next byte
rol N ; last byte
; C bit set if unsigned overflow
; V bit set if signed overflow
rts
--------------------------------------------------------------------------------------
32-bit signed shift right N=N>>1 on the 6812
N ds 4 ; 32-bit number
asr32 asr N ; start with most significant byte
ror N+1 ; next byte
ror N+2 ; next byte
ror N+3 ; last byte
; C bit set if you should round up
rts
;with rounding
asr32r asr N ; start with most significant byte
ror N+1 ; next byte
ror N+2 ; next byte
ror N+3 ; last byte
; C bit set if you should round up
bcc Done
inc N+3 ; round up
bcc Done
inc N+2 ; round up
bcc Done
inc N+1 ; round up
bcc Done
inc N ; round up
Done rts
--------------------------------------------------------------------------------------
32-bit unsigned shift right N=N>>1 on the 6812
N ds 4 ; 32-bit number
lsr32 lsr N ; start with most significant byte
ror N+1 ; next byte
ror N+2 ; next byte
ror N+3 ; last byte
; C bit set if you should round up
rts
;with rounding
lsr32r lsr N ; start with most significant byte
ror N+1 ; next byte
ror N+2 ; next byte
ror N+3 ; last byte
; C bit set if you should round up
bcc Done
inc N+3 ; round up
bcc Done
inc N+2 ; round up
bcc Done
inc N+1 ; round up
bcc Done
inc N ; round up
Done rts
This document has four overall parts
Overview
Syntax (fields, pseudo ops)
Local variables
Examples