8085 Assembly looping assistance (Resolved)

Thread Starter

keiichicom

Joined Apr 26, 2022
76
Hi,

I have this program that stores the number of bytes to send, stores the message to send in memory and then bit bangs the SOD port on the 8085 and it's supposed to display this message:

Welcome to the 8085 Monitor
>

But it does this and the program doesn't halt:

1711557987494.png

The d register contains decimal 31 (message + cr + lf + 1) so i decrement it and zero should be halting condition but it loops forever.
Please assist. Here is the code:

Welcome Message to 8085 Monitor:
       MVI A,1F
       STA 1000

       MVI A,57
       STA 1001
       MVI A,65
       STA 1002
       MVI A,6C
       STA 1003
       MVI A,63
       STA 1004
       MVI A,6F
       STA 1005
       MVI A,6D
       STA 1006
       MVI A,65
       STA 1007
       MVI A,20
       STA 1008
       MVI A,74
       STA 1009
       MVI A,6F
       STA 100A
       MVI A,20
       STA 100B
       MVI A,74
       STA 100C
       MVI A,68
       STA 100D
       MVI A,65
       STA 100E
       MVI A,20
       STA 100F
       MVI A,38
       STA 1010
       MVI A,30
       STA 1011
       MVI A,38
       STA 1012
       MVI A,35
       STA 1013
       MVI A,20
       STA 1014
       MVI A,4D
       STA 1015
       MVI A,6F
       STA 1016
       MVI A,6E
       STA 1017
       MVI A,69
                           STA 1018
       MVI A, 74
                           STA 1019
                           MVI A, 6F
                           STA 101A
                           MVI A, 72
                           STA 101B
                           MVI A, 0A
                           STA 101C
                           MVI A, 0D
                           STA 101D
       MVI A, 3E
                           STA 101E

       LXI H, 1000
       MOV D,M

       LXI H,1001

LXI SP,2000H
PUSH H

START:       MOV C,M    // Send a test character
                       

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
push h
   
                          DCR D
      JNZ START
 
Last edited:

Papabravo

Joined Feb 24, 2006
21,261
The JNZ instruction has nothing following it. If you had all NOP instructions, then the program counter would execute a bunch of NOP instructions and return to address 0 and start over again.

Alternatively, there might be an RST 0 (Restart 0 instruction after the JNZ with would also do the equivalent of a subroutine call to location 0.

You really have not provided enough information.

Also. Why are you using instructions to initialize the message?
 

Thread Starter

keiichicom

Joined Apr 26, 2022
76
Thanks, worked with HLT after the jnz start. I guess if I want a program to halt I should tell it to halt, lol .

I did it this way since It is my own circuit, not a 8085 kit and I am making my own software. I will be using the sid/sod ports for all communications...

Kei
 

MrChips

Joined Oct 2, 2009
30,946
Your code is storing hex values into memory, e.g.
MVI A,57
STA 1001

Do you know that the assembler will do this for you directly?
Check your assembler manual on how to reserve data bytes for bytes, double bytes and strings.

Also, you are mixing hexadecimal and decimal notation. It preferable to use decimal notation when decimal values are needed and use hexadecimal notation for binary or hexadecimal bytes, e.g. 57H, 0x57, or $57. Check the manual for the accepted representation.
 

Thread Starter

keiichicom

Joined Apr 26, 2022
76
Hi MrChips,

I am using a very basic assembler that I am used to: GitHub - 8085simulator/8085simulator.github.io . When I have a chance I will pick a more fancy one. The notation for this assembler for hex is 09FEH for example but it seems the H is optional, or i will add the missing Hs

I just noticed the db directive in the manual so i can at least use that to store my string.

Thanks, Kei
 

Thread Starter

keiichicom

Joined Apr 26, 2022
76
Thanks, it is working now. I use an FTDI board for TTL 5V serial to RS232(simulated COM port via USB). I shorthened the message for testing. After pressing the 8085 circuit hardware reset button, the only issue I had was that either the first character wasn't sent properly or not interpreted properly by TeraTerm since 'Welcome' was displayed as 'elcome'. I will check with a logic analyzer later. As a work around, I just sent a leading space (which is probably still not interpreted properly).

Serial Output (9600,n,8,2 with CR+LF interpreted literally(AUTO in Setup->Terminal->Receive field)

teraterm.PNG

8085 Assembly Code


MVI D, 0BH
LXI SP,2100H
MVI A, 20
STA 2000H
MVI A, 57
STA 2001H
MVI A,65
STA 2002H
MVI A,6C
STA 2003H
MVI A, 63
STA 2004H
MVI A,6F
STA 2005H
MVI A,6D
STA 2006H
MVI A,65
STA 2007H
MVI A,0D
STA 2008H
MVI A,0A
STA 2009H
MVI A,3EH
STA 200AH
LXI H,2000H
START: PUSH H
MOV C,M
COUT:
di
mvi b,0BH ; Number of output bits
xra a ; Clear carry for start bit
CO1:
mvi a,080H ; Set the SDE flag
rar ; Shift carry into SOD flag
cmc ; and invert carry. Why? (serial is inverted?)
sim ; Output data bit
lxi h,0112h ; 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,03fffH ; Wait a while before sending the character again
CHILL:
dcr l
jnz CHILL
dcr h
jnz CHILL
POP H
INX H
dcr d
jnz START
hlt


- Kei
 
Last edited:
Top