Class Notes 2012/02/10


ORG $800
vec1 dc.b 1,2,3,4,$FF
vec2 dc.b 0, $FF, 3, 5, $80
count ds.b 1
ORG $4000
ldx #vec1 ; x->vec1
ldy #vec2 ; y -> vec2
ldab #5 ; init loop counter
clr count ; clears the count
loop: ldaa 1,x+ ;vec1[i] -> A
cmpa 1,y+ ;compare vec1[i] with vec2[i]
blt next ;if vec1[i] < vec2[i] then branch
inc cont
next: dbne b, loop dec. loop counter + branch if it's !=0

Next example: Write a program to compute the dot product of vectors a + b. Assume the vectors contain unsigned 8-bit values and ignore any carries...

a (dot) b = sum from i to n of a_i*b_i = a1*b1 + a2*b2 + ... a_n*b_n

; Variables
vecA ds.b 5
vecB ds.b 5
result ds.w 1
counter ds.b 1

; Code
ORG $4000
ldx #vecA
ldy #vecB
movb #5, counter
movw #0, result ; We move word because multiplying two bit numbers results in word (???)
loop: ldaa 1,x+
ldab 1,y+
mul
addd result ; Goes into register D
std result ; Put the result stored in D back into result.
dec counter
une loop ; ??


HW # 4
RAMStart $0800
ROMStart $4000

; Initialize SP to $1000

samples ds.b $10,$20,$30,$90
psum ds.b 5


;Submit:
;Screen captures after the 3rd, 4th, 5th addition is completed...
;Generate and submit a list file
;Record 4 flags (N,Z,C,V)
;Determine if an where overflow occurs.
;What is the final sum in decimal?
;Is the final sum a valid signed result?

; Due next Friday (17 Feb 2012)

; Example "stall" loop until bit 2 of 'u' is 0

here: brset u,%00000100, here ; Polling loop...

;Logic
; Performa bit-wise boolean logic operation between a register r (A,B, CCR) and a memory operand.

; Result saved in the register;
; ... see slides for more info...

;Example:
If mem. location $10 contains $B3 and register A contains $64, what is the result of the following instruction?

; ANDA $10, ANDA #$40, ORAA $10, ORAA #$10, EOR $10

ANDA $10 ; A 0110 0100
($0010) 1011 0011
0010 0000 (result)

ANDA #$10 ; A 0110 0100
0001 0000
0000 0000 (result)

ORAA $10 ; A 0110 0100
1011 0011
1111 0111 (result)

EORA $10 ; A 0110 0100
1011 0011
1101 0111 (result)

; CCR Logic operations
; SXHINZVC
; Set N + C flags:
ORCC #%00001001

;clear 2+V flags:
ANDCC #%11111001

; Example: Write a loop to toggle LEDs connected to PORTA

ldda #$0
eora #$FF ; =%1111 1111
staa PORTA
;some sort of delay
bra loop


;BITr, BSET, BCLR ...

;BSET Set bits in a memory operand by performing ...

;Example
bset var1, #%0001111 ; set the lower 4 bits of var1
variable bit "mask"

bclr var1, #11110000 ; clear upper 4 bits

; Logical Shifts
;Left Shift
LSL, LSLA, LSLB, LSLD

;Right Shift
LSR, LSRA, LSRB, LSRD

; Arithmetic Shift
;Left
; ASL, ASLA, ASLB, ASLD

;Right
; ASR, ASRA, ASRB, ASRD

;Example 7.22 from book
; Write a program to multiply a 16-bit number in D by 10 using arithmetic shift instead of the 'emul' (extended multiply instruction);

temp ds.w 1
std temp
asld ; our value is multiplied by 2x
asld ; our value is multiplied by 2x
addd temp ; Add one more value. Our value is now 5x larger
asld ; D is now 10x


Comments

Popular posts from this blog

Using Audacity as an Oscilloscope

Using Google Command Line Tools to post my Computer Systems Notes

Tracking an LED with OpenCV