



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Write a program segment to reverse the bit order of a 6-bit number. Assume this number is stored in $6000. Store the reversed number to $6001 (i.e., if the original number is 0 0 b 5 b 4 b 3 b 2 b 1 b 0 , after this program, the number in $6001 will be 0 0 b 0 b 1 b 2 b 3 b 4 b 5 ). Reversing a number can be easily accomplished by rotating the number 1-bit at a time, until the desired rotation is accomplished. First, start the process by rotating the LSB out of the original number and into the carry register. Then rotate this number into the LSB of another register, and repeat this process. Each subsequent rotation will “push” the last rotation forward until all bits are in their correct places. This can be accomplished with a series of shifts, or with a loop. ORG $4000 ; Set program start address LDAA $6000 ; Load original number in register A LDAB #$00 ; Initialize register B LSRA ; Shift LSB out of original number and into carry register ROLB ; Rotate bit in carry register into LSB of register B ; Now register B = 0000000b 0 LSRA ; Shift LSB out of original number and into carry register ROLB ; Rotate bit in carry register into LSB of register B ; Now register B = 000000b 0 b 1 LSRA ; Shift LSB out of original number and into carry register ROLB ; Rotate bit in carry register into LSB of register B ; Now register B = 00000b 0 b 1 b 2 LSRA ; Shift LSB out of original number and into carry register ROLB ; Rotate bit in carry register into LSB of register B ; Now register B = 0000b 0 b 1 b 2 b 3 LSRA ; Shift LSB out of original number and into carry register ROLB ; Rotate bit in carry register into LSB of register B ; Now register B = 000b 0 b 1 b 2 b 3 b 4 LSRA ; Shift LSB out of original number and into carry register ROLB ; Rotate bit in carry register into LSB of register B ; Now register B = 00b 0 b 1 b 2 b 3 b 4 b 5 STAB $6001 ; Store the results and stop the program SWI
that a bit can be negated by using an exclusiveOR with the binary value ‘1’. Therefore a full 8-bit negation can be accomplished by exclusiveOR with $FF. Not (X) = ExclusiveOR(X,$FF) NEGATE_MASK EQU $FF ; Create an equate for the negation mask BASE1 EQU $5000 ; Base of 1st number BASE2 EQU $5010 ; Base of 2nd number NEGATED_BASE EQU $5020 ; Base of negated version of 2nd number RESULT_BASE EQU $6000 ; Base of result ORG $4000 ; Set program start address ; Convert the second number to negative in 2’s complement ; First Negate the 2nd number 1 byte at a time LDAA BASE2+0 ; Read in byte EORA #NEGATE_MASK+0 ; Negate it STAA NEGATED_BASE+0 ; Store the result LDAA BASE2+1 ; Do this for the remaining 2 bytes EORA #NEGATE_MASK STAA NEGATED_BASE+ LDAA BASE2+ EORA #NEGATE_MASK STAA NEGATED_BASE+ ; Now perform 2's complement addition ; NUM1 - NUM2 = NUM1 + (Negated NUM2) + 1 ; Pre-load the carry bit with 1 LDAA #$01 ; Load a 1 into A, and shift the 1 into the carry reg LSRA ; Now begin the addition starting with the least-signficant byte LDAA BASE1+2 ; Load in byte of NUM ADCA NEGATED_BASE+2 ; Add negated byte with carry STAA RESULT_BASE+2 ; Use carry (with carry pre-set to 1) LDAA BASE1+1 ; Continue for remaining bytes ADCA NEGATED_BASE+ STAA RESULT_BASE+1 ; Use carry again LDAA BASE1+ ADCA NEGATED_BASE+ STAA RESULT_BASE+0 ; Use carry again SWI ; Stop the program
If A contains $56, what is the result of each of the following instructions? Assume that A is restored to its original value before each instruction. a) ANDA #$ A = $56 = 0101_ Mask = $33 = 0011_ Result(AND) = 0001_0010 = $ A = $ b) ORAA #$ A = $56 = 0101_ Mask = $33 = 0011_ Result(OR) = 0111_0111 = $ A = $ c) EORA #$ A = $56 = 0101_ Mask = $33 = 0011_ Result(EOR) = 0110_0101 = $ A = $ d) BITA #$ The BITA operation performs arithmetic, but does not alter the contents of register A. However, it does alter the contents of the CC register. Typically this instruction will be used for the sake of comparison before a branch instruction, so that CCR bits can be purposefully set w/o having to alter any of the values in registers.