Hi,
I was trying to remove the "spaghetti" from my spaghetti code and now it doesn't work. It displays the banner and then some junk characters in teraterm and doesn't wait for user input:
Non-working code:
Program Working in Teraterm With Old Code:
![teraterm2.PNG teraterm2.PNG](https://forum.allaboutcircuits.com/data/attachments/306/306841-8b4ae7051cdf3b47e973ddbe6ecde0f5.jpg)
Any help with this is appreciated,
- Kei
I was trying to remove the "spaghetti" from my spaghetti code and now it doesn't work. It displays the banner and then some junk characters in teraterm and doesn't wait for user input:
Non-working code:
Non-working Code:
;8085 Monitor
LXI SP,7FFFH
JMP START
# ORG 0006H ; Banner
# DB DATA:20H,0DH,0AH,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 0039H ; menu
# DB DATA:0DH,0AH,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, 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, 73H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 28H, 72H,65H,73H,65H,74H,29H, 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, 30H, 30H, 30H, 30H, 68H, 0DH,0AH,3EH
# ORG 0168H ; display banner
START:
LXI H,0006H
MVI D,00H
MVI E,33H ; count of chars in hex in DE
CALL COUT
MENU: CALL CIN ; display menu and wait for user input
LXI H,0039H
MVI D, 01H
MVI E, 2FH ; count of chars in hex in DE
CPI 68H
jz COUT
cpi 73h
jz START
jmp MENU ; loop forever
COUT: PUSH H ; output characters to serial port
MOV C,M
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 COUT
pop psw
RET
CIN: ; input character from serial port
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
Working Code:
# ORG 01000H
# DB DATA:20H,0DH,0AH,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 02000H
# DB DATA:0DH,0AH,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, 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, 73H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 20H, 28H, 72H,65H,73H,65H,74H,29H, 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, 30H, 30H, 30H, 30H, 68H, 0DH,0AH,3EH
# ORG 0000H
LXI SP,03000H
MVI D,00H
MVI E,33H
LXI H,01000H
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,02000H
MVI D, 01H
MVI E, 2FH
jz start
cpi 73h
jz 0000h
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
![teraterm2.PNG teraterm2.PNG](https://forum.allaboutcircuits.com/data/attachments/306/306841-8b4ae7051cdf3b47e973ddbe6ecde0f5.jpg)
Any help with this is appreciated,
- Kei