Hi,
For the life of me, I can't figure out why this is happening. Pressing h the first time displays the help message but the second time it starts displaying Us after printing a few correct characters. Any assistance with fixing this bug would be appreciated.

8085 Assembly Code
For the life of me, I can't figure out why this is happening. Pressing h the first time displays the help message but the second time it starts displaying Us after printing a few correct characters. Any assistance with fixing this bug would be appreciated.

8085 Assembly Code
# ORG 0100H
# DB DATA:20H, 57H, 65H, 6CH, 63H, 6FH, 6DH, 65H, 20H, 74H, 6FH, 20H, 74H, 68H, 65H, 20H, 38H, 30H, 38H, 35H, 20H, 4DH, 6FH, 6EH, 69H, 74H, 6FH, 72H, 0DH, 0AH, 50H, 72H, 65H, 73H, 73H, 20H, 68H, 20H, 66H, 6FH, 72H, 20H, 68H, 65H, 6CH, 70H, 0DH, 0AH, 3EH
# ORG 0200H
# DB DATA:38H, 30H, 38H, 35H, 20H, 4DH, 6FH, 6EH, 69H, 74H, 6FH, 72H, 20H, 48H, 65H, 6CH, 70H, 0DH, 0AH, 0DH, 0AH, 4CH, 65H, 67H, 65H, 6EH, 64H, 3AH, 20H, 78H, 78H, 78H, 78H, 68H, 20H, 73H, 74H, 61H, 72H, 74H, 69H, 6EH, 67H, 20H, 6DH, 65H, 6DH, 6FH, 72H, 79H, 20H, 61H, 64H, 64H, 72H, 65H, 73H, 73H, 2CH, 20H, 78H, 78H, 68H, 2CH, 20H, 79H, 79H, 68H, 2CH, 20H, 7AH, 7AH, 68H, 2CH, 2EH, 2EH, 2EH, 20H, 64H, 61H, 74H, 61H, 0DH, 0AH, 0DH, 0AH, 77H, 20H, 78H, 78H, 78H, 78H, 68H, 20H, 78H, 78H, 68H, 2CH, 20H, 79H, 79H, 68H, 2CH, 20H, 7AH, 7AH, 68H, 2CH, 20H, 2EH, 2EH, 2EH, 20H, 77H, 72H, 69H, 74H, 65H, 20H, 64H, 61H, 74H, 61H, 20H, 74H, 6FH, 20H, 52H, 4FH, 4DH, 20H, 0DH, 0AH, 0DH, 0AH, 72H, 20H, 78H, 78H, 78H, 78H, 68H, 20H, 78H, 78H, 68H, 2CH, 20H, 79H, 79H, 68H, 2CH, 20H, 7AH, 7AH, 68H, 2CH, 20H, 2EH, 2EH, 2EH, 20H, 72H, 65H, 61H, 64H, 20H, 64H, 61H, 74H, 61H, 20H, 66H, 72H, 6FH, 6DH, 20H, 52H, 4FH, 4DH, 0DH, 0AH, 0DH, 0AH, 65H, 20H, 78H, 78H, 78H, 78H, 68H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 65H, 78H, 65H, 63H, 75H, 74H, 65H, 73H, 20H, 74H, 68H, 65H, 20H, 70H, 72H, 6FH, 67H, 72H, 61H, 6DH, 20H, 61H, 74H, 20H, 78H, 78H, 78H, 78H, 68H, 0DH, 0AH, 0DH, 0AH, 72H, 20H, 20H, 20H, 20H, 20H, 20H,20H,20H,20H, 20H,20H,20H,20H, 20H, 20H, 20H, 20H, 20H, 20H,20H, 20H, 20H, 20H, 20H, 20H, 20H, 65H, 78H, 65H, 63H, 75H, 74H, 65H, 73H, 20H, 74H, 68H, 65H, 20H, 70H, 72H, 6FH, 67H, 72H, 61H, 6DH, 20H, 30H, 30H, 30H, 30H, 68H
# ORG 0000H
LXI SP,0800H
MVI D,00H
MVI E,31H
LXI H,0100H
START: PUSH H
MOV C,M
COUT: DI
MVI B,0B // Number of output bits
XRA A // Clear carry for start bit
CO1: MVI A,80 // Set the SDE flag
RAR // Shift carry into SOD flag
CMC // and invert carry. Why? (serial is inverted?)
SIM // Output data bit
LXI H,0112 // Load the time delay for one bit width
CO2: DCR L // Wait for bit time
JNZ CO2
DCR H
JNZ CO2
STC // Shift in stop bit(s)
MOV A,C // Get char to send
RAR // LSB into carry
MOV C,A // Store rotated data
DCR B
JNZ CO1 // Send next bit
EI
LXI H,3FFF // Wait a while before sending the character again
CHILL: DCR L
JNZ CHILL
DCR H
JNZ CHILL
POP H
INX H
DCX D
push psw
MOV A, D ; Move the content of register D into the accumulator A
ORA E ; Logical OR operation with register E
Jnz start
pop psw
menu: CALL CIN
CPI 68H
LXI H,0200H
MVI D, 01H
MVI E, 29H
jz start
jmp menu
CIN:
di
push b
mvi b,09 ; Loop count is number of bits to be read minus one
CI1: ; does not include stop bits
rim ; Wait for a zero indicating a start bit
ora a
jm CI1
lxi h,0109H ; delay a half bit time to get to the middle of the start bit
CI2:
dcr l
jnz CI2
dcr h
jnz CI2
CI3:
lxi h,0112H ; delay to the middle of the next data bit
CI4:
dcr l
jnz CI4
dcr h
jnz CI4
rim ; read the next data bit
ral ; shift the data bit into the carry flag
dcr b ; exit if all of the bits have been read
jz CI5
mov a,c ; character in progress into A
rar ; shift the data bit from carry into the MSB
mov c,a ; store the character back into C
jmp CI3 ; get the next bit
CI5:
mov a,c ; return the character in A
pop b
ei
ret
Last edited: