In: Computer Science
Make assembly code that accomplishes the following: load a number into accumulator A 2. logical shift right of A 3. If the carry bit of CCR sets (use instruction “bcs”), then steadily display a “1” on a seven- segment display block. 4. If the carry bit is not set, then steadily display a “0” on a seven-segment display block. 5. Change to another number and run the code, again, so that you can see either 1 or 0 displayed.
Answer : Given data
EXPLANATION of each line of code is given in comments after ;
Begin : LDAA #$55 ;to load any
number into accumulator
lsra; Accumulator A is shifted right one place
lbcs display_one; jump to display_one if the C flag (= LSB bits) is
1
org $1000 ;if Carry flag is not set (0) then display zero, follow
this code
four equ $30; seven-segment pattern of digit 0
org $1500 ; origin address of code
movb #$0F,DDRP; to configure PORT P for output
movb #$FF,DDRB; to configure PORT B for output
bset PTP,$0D ;disable the remaining digits by setting the digits to
1
bclr PTP,$02 ;enable the required digit by setting it to 0
movb #$3f,PTB; output the seven-segment pattern to PORTB
swi
jmp begin ; jump to start of program after
displaying 1
display_one : org $1000 ; code of display 1
when carry flag is set
four equ $7E; seven-segment pattern of digit 0
org $1500 ; origin address of code
movb #$0F,DDRP; configure PORT P for output
movb #$FF,DDRB; configure PORT B for output
bset PTP,$0D ;disable the remaining digits by setting the digits to
1
bclr PTP,$02 ;enable the required digit by setting it to 0
movb #$3f,PTB; output the seven-segment pattern to PORTB
swi
jmp begin ; jump back to start of program after
displaying 0
____________THE END_______________