Class Notes 2012/02/17


; ASCII to packed BCD
; 1 3 5 8 7 6
; $31 $33 $35 $38 $37 $36
;
; |$31| <= ASCII
; |$33|
; |$35|
; |$38|
; |$36|
; |$13| <= PBCD
; |$58|
; |$76|
; | |
; | |

;Code:
ASCII dc.b '125876'
PBCD ds.b 3
count ds.b 1

ldx #ASCII
ldy #PBCD
movb #3,count ; initializes the loop counter
loop:
ldaa 1,x+ ; gets 1st char
lsla ; shift left
lsla ; shift left
lsla ; shift left
lsla ; shift left
ldab 1,x+ ;get next character
andb #$0F ;AND it with %0000 1111, which leaves us with the least signif bit of next character
aba ;add B to A
staa 1,y+ ;store in PBCD
dec count ;decrement loop counter
bne loop ;branch if != 0

;================================================================
;HW #5
;The array "sample" contains 8 8-bit signed binary numbers (integers) as shown below. Write a program which computes the sum of positive numbers and the sum of negative number, and stores them in psum and nsum, respectively.
;It also computes the sum of the absolute values of all the numbers and stores it inn tsum.
;Note that the value in tsum is ito be interpred as an unsigned number.
;Your program should work for any 8 numbers...
; 2 Versions:
;Turn in:
;Version 1:
; Source , regiester and memory windows.
; Use bpl, bmi to check the sign in 'samples'
;
;
;Version 2:
; Use brset, brclr to check the sign in 'samples'


;Example:
; HW 5
; initialize all vars
; clear psum,nsum
;set up any index registers
; init. loop counter

loop: ;
;check 1 byte of 'samples'
;if samples is positive, branch to 'pos'
;else, 'samples' is neg
;add 'samples' to our negative sum, 'nsum'
;branch to 'next'

positive: ;
; we know samples is positive
; add value to 'psum'

next: ;
; decrement loop counter
; branch if != 0 to loop

end; ;
;at end of loop, calculate total
;tsum = psum + complement/negate of (nsum)
; or tsum = psum - (nsum) (nsum is negative)
;
; Lab 4 -- Dr. Nelson what HCS12X

Comments

Popular posts from this blog

Using Audacity as an Oscilloscope

Using Google Command Line Tools to post my Computer Systems Notes

Store Script Passwords Securely in Mac OS X