Question
I need help finishing my assembly code. At the end of the instruction I am displaying the code that I have. I just need to
I need help finishing my assembly code. At the end of the instruction I am displaying the code that I have. I just need to insert these last instructions into the main loop of the code.
These are the instructions:
Take a 4-bit input number and convert into a BCD number which is the decimal equivalent of the input number. To do the conversion, the input number is checked against the value 0x09. If it is greater than 9, then add a constant 0x06 to it. If it is less than 9, then no addition of the constant is needed.
For example: a) If input = 0x08, then output = 0x08 (no change)
b) If input = 0x0b, then output = 0x0b + 0x06 = 0x11. 0x0b has the decimal equivalent of 11. This will the number 11 which is the decimal equivalent of 0x0b
c) If input = 0x0d, then output = 0x0d + 0x06 = 0x13 because 0x0d is 13 in decimal.
To implement the operation, here are some steps: 1) Read the input into the variable InA
2) Load a constant 0x09 into W
3) Use the instruction CPFSGT (see reference) to compare the value in InA against the W register (that contains 0x09). If InA is greater than 0x09, the next instruction below this instruction is executed. Otherwise, the next instruction is skipped: CPFSLT InA, 1 (go here if greater or =) (go here if less)
*****CODE STARTS FROM HERE***********
#include
config OSC = INTIO67
config WDT = OFF
config LVP = OFF
config BOREN = OFF
InA equ 0x20
InB equ 0x21
Result equ 0x22
ORG 0x0000
START:
MOVLW 0x0F
MOVWF ADCON1
MOVLW 0xFF
MOVWF TRISA
MOVLW 0x00
MOVWF TRISB
MOVLW 0x00
MOVWF TRISC
MOVLW 0X00
MOVWF TRISE
MAIN_LOOP:
MOVF PORTA, W ; Read from PORTA and move it into W
ANDLW 0x0F ; Mask with 0x0F
MOVWF InA
MOVF PORTB, W
ANDLW 0x0F
MOVWF InB
XORWF InA, W
MOVWF Result
MOVFF Result, PORTC
BCF PORTE, 2
BNZ JUMP
BSF PORTE, 2
JUMP:
GOTO MAIN_LOOP
END
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started