Class Notes 2012/03/02


Rewrite find-min to pass parameters via the stack

ORG $0800
array ds.b 5
min ds.b 1
ORG $4000
lds #$1000
ldx #array
pshx
ldab #5
pshb
bsr find_min
pula
staa min
leas 2,SP ;clean up the stack...

find_min:
;Finds the min value
; Registers modified:
Variables modified:
Input parameters:
; addr of array: SP + 2
; lenth of array: SP + 3
;Output parameters:
; min value:
ldx 3,SP ;x -> addr of array
ldab 2,SP ;B = length of array
loop:
; compare + loop;
; what we did in previous example...
; see find_min sub from Wednesday.
dbne b,loop
staa 2,SP
rts

; | |
; --------
; | |
; --------
; |return| <--SP
; --------
; |addr. |
; --------
; |length| <--SP + 2
; --------
; |addres| <--SP + 3
; --------
; |of arr|
; --------
; | | $1000
; --------
; | |
; --------


Review of HW 7:
lmax = min(7,2l)
lmin = max(0,2l-7)

B(2): lmax = min(7,4) = 4 B(4) = %0001 0000
lmin = max(0,-3) = 0 B(0) = %0000 0001
B(6): lmax = min(7,12) = 7 B(7) = %1000 0000
lmin = max(0,5) = 5 B(5) = %0010 0000

The sequence:
B(l) -> B(lmin) -> B(lmax) -> B(l)
B(2) -> B(0) -> B(4) -> B(2) B(2->1->0->2->3->4->3->2) 8 shifts
B(6) -> B(5) -> B(7) -> B(6) B(6->5->6->7->6) 4 shifts

# shifts = (lmax - lmin) * 2

main:
;initialize global vars
; stack pointer
; level -> B(5),B(3)
; direction
;
;call subroutine init_vars
; -> compute max for given level
; -> compute min for given level
; -> sequence link (number of shifts)
; -> initialize "LEDS"

; call subroutine update_leds
; -> check the ends (and update direction)
; -> shift LEDS once per call
;
; dec_counter
; -> counter = number of shifts
;
;
;end

init_vars:
compute lmax
compute lmin
compute # of shifts
init LEDS
rts

update_leds:
left end?
yes: set dir right
no: right end?
yes: set dir left
no: next...
dir?
left: shift left
right: shift right

rts


...

Comments

Popular posts from this blog

Using Audacity as an Oscilloscope

Using Google Command Line Tools to post my Computer Systems Notes

Ping utility that targets a specific port