### Class Notes 2012/02/13

; #1 Write a program to compute the following

;A1 = (B1 - C1) - (D1 + 8)

;Use only direct/extended addr. for all memory references.

ldea B1; A=B1

suba C1 ; A = (B1-C1)

ldab D1 ; B = D1

addb #8 ; B = (D1 + 8)

sba ;

staa A1 ;

;Use only constant offset indexed addr. for all memory references.

ldx #A1

ldaa 1,x ;A=B1

suba 2,x ; A=(B1-C1)

ldab 3,x ;B=D1

addb #8 ;B= D1+8

sba ;A=(B1-C1) - (D1 + 8)

staa 0,x ; staa x

;Use auto-increment indexed addr. for all mem references.

ldx #A1 ;

ldaa 1,+x ; A = B1

suba 1,+x ; A = (B1 - C1)

ldab 1,+x ; B = (D1)

addb #8 ; B = (D1 + 8)

sba ; A = (B1-C1) - (D1 + 8)

staa 3,-x ; A1 = A

;Use register offset indexed addr. for all mem references.

ldx #41

ldab #1

ldaa b,x ; A = B1

ldab #2

suba b,x ; A = (B1 - C1)

ldab #3

suba b,x ;A = (B1 - C1) - D1

suba #8 A = B1 - C1 - D1 - 8

ldab #0

staa b,x A1 = A

;Define 2 20-byte arrays,

; 1) Copy one byte at a time, using indexed addressing but without using auto-increment (or decrement).

ary1 ds.b 20

ary2 ds.b 20

ldab #20

ldx #0

loop:

ldaa ary1,x ;ary1[i]

staa ary2,x ;ary2[i]

in x

dbne b,loop

2) Copy one byte at a time, using auto-increment.

ary1 ds.b 20

ary2 ds.b 20

ldab #20

ldx #ary1

ldy #ary2

loop: ldaa 1,x+ ;movb 1, x+,1,y+

staa 1,y+ ;movb 1, x+,1,y+

dbne b,loop

3) Copy one word at a time using auto-inc.

ldab #10

ldx #ary1

ldy #ary2

loop: mov2 2,x+,2,y+

dbne b,loop

## Comments

## Post a Comment