Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

assembly programming 8085

Status
Not open for further replies.

meowth08

Member
Hi,

I am beginning to learn assembly programming.
This is my first homework. Hopefully I will be able to get it.

I am tasked to create a routine (using 8085 instructions) of an 8 bit counter (00 to FF).

The counter works like this.
It has “count up” and “count down” buttons.
It starts in 00.
If I press “count up”, 00 becomes 01.
If I press “count up” again, 01 becomes 02.
If I press “count up” again, 02 becomes 03.
When I press “count down”, 03 becomes 02.
The increment/decrement is always 01.

Note:
When the count is 00 and “count down” is pressed, the 00 count remains.
Also, when the count is FF and “count up” is pressed, the FF count remains.

Please help me with the programming. Thank you in advance.
If you can give me the exact code, I believe it will be very helpful on my part.
I’ll just have to simulate it in the simulator that I downloaded and study how the step by step mnemonics work.

meowth08
 
Hi,

I got the simulator here for free. :) **broken link removed**

I have tried running some sample programs but I was not able to do the task given. That is also because I don't know exactly what the mnemonics do.

m8
 
This is the program my friend gave me WITH RESET.

START :
MVI B,00H //initialization of register B

INPUT :
IN 00H //gets input from port (00H);

RESET :
CPI 01H //compares input to byte "01H" to reset
JZ INPUT //if reset, return to INPUT
JNZ IORD //if no reset, go to IORD

IORD :
CPI 02H //compares input to byte "02H" to decide INR or DCR
JZ INCREMENT //if A(INPUT)=02H, go to INCREMENT
JNZ DECREMENT //if not, go to DECREMENT

INCREMENT :
INR B //B=B+1
MOV A,B //A=B
OUT A0H //Output A to port (A0H)
CPI FFH //Compare if A is "FFH"
JZ 0820H //if A=FFH, Output to port (A0H)
JNZ INPUT //if not, return to INPUT
OUT A0H
JMP 0820H //arbitrary command to latch "FFH" on port (A0H)

DECREMENT :
DCR B //B=B-1
MOV A,B //A=B
OUT A0H //Output A to port (A0H)
CPI 00H //Compare if A is "00H"
JZ 0831H //if A=FFH, Output to port (A0H)
JNZ INPUT //if not, return to INPUT
OUT A0H
JMP 0831H //arbitrary command to latch "00H" on port (A0H)

I have followed the steps of the program. But there are some mistakes I think on that par of the INPUT:

Basically, the program will not run on the simulator. But changing the INPUT to MVI A, 01H will do. or MVI A,02H.

01H from the program is reset and 02H is increment.

Is there a way to get away from manual changing of INPUT?
 
There is no way for your code to return from the "JZ 0820h" and the "JZ 0831h" when there is no change... ie.. if 0A0h = 0, it spasms or if it hits 0FFh, it spasms..

If the modify is successful the code resets and it starts again otherwise it faults..

I think it needs a new line that keeps the port at FF or 00.
 
Last edited:
Hello,

The code tags make code more readable, and it makes it easier to get better quality responses. Like this:

Code:
START :
MVI B,00H //initialization of register B

INPUT :
IN 00H //gets input from port (00H);

RESET :
CPI 01H //compares input to byte "01H" to reset
JZ INPUT //if reset, return to INPUT
JNZ IORD //if no reset, go to IORD

IORD :
CPI 02H //compares input to byte "02H" to decide INR or DCR
JZ INCREMENT //if A(INPUT)=02H, go to INCREMENT
JNZ DECREMENT //if not, go to DECREMENT

INCREMENT :
INR B //B=B+1
MOV A,B //A=B
OUT A0H //Output A to port (A0H)
CPI FFH //Compare if A is "FFH"
JZ 0820H //if A=FFH, Output to port (A0H)
JNZ INPUT //if not, return to INPUT
OUT A0H
JMP 0820H //arbitrary command to latch "FFH" on port (A0H)

DECREMENT :
DCR B //B=B-1
MOV A,B //A=B
OUT A0H //Output A to port (A0H)
CPI 00H //Compare if A is "00H"
JZ 0831H //if A=FFH, Output to port (A0H)
JNZ INPUT //if not, return to INPUT
OUT A0H
JMP 0831H //arbitrary command to latch "00H" on port (A0H)

In addition to what Ian said,


Notice this snippet:

Code:
JZ INPUT //if reset, return to INPUT
JNZ IORD //if no reset, go to IORD

IORD :
CPI 02H //compares input to byte "02H" to decide INR or DCR

The line JNZ IORD is useless. It is useless to consume two bytes in a jump, when the location you're jumping into is the natural next instruction: The one just below.

If it's zero, then you jump to INPUT .. IORD is just below that line, so you can just let it roll to have the same result. In other words, if you delete that line : If the zero flag is set, it jumps to INPUT, *else* CPI 02H is the next instruction that will be executed.

So the code becomes:

Code:
JZ INPUT //if reset, return to INPUT

IORD :
CPI 02H //compares input to byte "02H" to decide INR or DCR


The same logic can be applied to this :

Code:
JZ INCREMENT //if A(INPUT)=02H, go to INCREMENT
JNZ DECREMENT //if not, go to DECREMENT
INCREMENT :
INR B //B=B+1
MOV A,B //A=B
OUT A0H //Output A to port (A0H)
CPI FFH //Compare if A is "FFH"
JZ 0820H //if A=FFH, Output to port (A0H)
JNZ INPUT //if not, return to INPUT
OUT A0H
JMP 0820H //arbitrary command to latch "FFH" on port (A0H)
 
DECREMENT :
DCR B //B=B-1
MOV A,B //A=B
OUT A0H //Output A to port (A0H)
CPI 00H //Compare if A is "00H"
JZ 0831H //if A=FFH, Output to port (A0H)
JNZ INPUT //if not, return to INPUT
OUT A0H
JMP 0831H //arbitrary command to latch "00H" on port (A0H)

Which you can transform to:

Code:
JNZ DECREMENT //if not, go to DECREMENT

INCREMENT :
INR B //B=B+1
MOV A,B //A=B
OUT A0H //Output A to port (A0H)
CPI FFH //Compare if A is "FFH"
JZ 0820H //if A=FFH, Output to port (A0H)
JNZ INPUT //if not, return to INPUT
OUT A0H
JMP 0820H //arbitrary command to latch "FFH" on port (A0H)
 
DECREMENT :
DCR B //B=B-1
MOV A,B //A=B
OUT A0H //Output A to port (A0H)
CPI 00H //Compare if A is "00H"
JZ 0831H //if A=FFH, Output to port (A0H)
JNZ INPUT //if not, return to INPUT
OUT A0H
JMP 0831H //arbitrary command to latch "00H" on port (A0H)

You just eliminated the line:
Code:
JZ INCREMENT //if A(INPUT)=02H, go to INCREMENT
and saved two bytes. Plus the other two bytes.


Here's a URL that can help a bit: https://www.cavehill.uwi.edu/fpas/cmp/online/el21c/lesson18.html

Plus the Datasheet you can search for. It contains the instruction set. That's the first thing I do when I need to program something: getting to know it.

All the best,
 
Last edited:
Jugurtha!! That's all well and good..... but the fact still remains... the code doesn't work Reg B inc's and dec's.... but JZ isn't working... The output is when an adjustment is made, but the code fails when an adjustment isn't required...
 
You're right. That's why I said "In addition to what Ian said". It's just a reminder for things to improve after he fixes the issues you spotted. The program needs to work first, of course. Then be enhanced.
 
Tell me about it ! It's frustrating. The fact you can't learn without spending a lot of time in front of your computer, and the fact that it doesn't help your eyes ... Arrhgggg!!
 
Hi,

The program I posted was from my friend.

I have a version of mine and I think I would understand your comments better if we use my own program.

However, I want to post it using the code tag as suggested by Jugurtha. How would I do that? Thanks.

m8
 
Code:
START:
	LXI B,FF00H		**load immediate BC
	LXI D,0102H		**load immediate DE
	MOV A,B		        **move content of B to A
	OUT 10H		        **output content of accumulator to port “10”

INPUT:
	IN 00H			**gets input from port “00”

RESET:
	CMP C			**input compared to content of C
	JZ INPUT			**if INPUT=C, get another input
	JNZ COMPARE		**if INPUT is not = C, go to COMPARE

COMPARE:
	CMP D			**compare input to D
	JZ CMPINR		**if INPUT=D, go to CMPINR
	JNZ CMPDCR		**if INPUT is not = D, go to CMPDCR

CMPINR:
	MOV A,B	        	**move content of B to A
	CPI FFH			**compare if content of accumulator is FF
	JZ FFSTATE		**if A=FF, go to FFSTATE
	JNZ INR			**if A is not =FF, go to INR

INR:
	INR B			**increment B by 1
	MOV A,B		        **move contents of B to A
	OUT 10H		        **output content of accumulator to port 10
	JMP INPUT		**get another input

CMPDCR:
	MOV A,B		        **move content of B to A
	CPI 00H		        **compare if content of accumulator is 00
	JZ 00STATE		**if A=00, go to 00STATE
	JNZ DCR		        **if A is not = to 00, go to DCR

DCR:
	DCR B			**decrements B by 1
	MOV A,B		        **move contents of B to A
	OUT 10H		        **output content of accumulator to port 10
	JMP INPUT		**get another input

FFSTATE:
	MVI A,FFH		        ** content of A becomes FF
	OUT 10H		        **output content of the accumulator to port 10
	JMP INPUT		**get another input

00STATE:
	MVI A,00H		**content of A becomes 00
	OUT 10H		        **output content of accumulator to port 10
	JMP INPUT		**get another input

This is my version of the program. Please check also on the comments if I am understanding fully every part of it. Thank you.
 
Hi,

Thanks Ian Rogers.

The first one was made by my best classmate who happens to be my friend.

He finished first and gave me his program.

That's why I had all the chance to study it and make revisions.

meowth08
 
Code:
INITIALIZE/RESET:
			MVI B,0FFH
			MOV A,B
			OUT 02H
INPUT:
			IN 01H
RESET/INC/DEC:
			CPI 01H
			JZ INITIALIZE/RESET
			CPI 02H
			JZ INCREMENT
			CPI 04H
			JZ DECREMENT
			JNZ INPUT
INCREMENT:
			MOV A,B
			CPI 0FFH
			JZ FFSTATE
			INR B
			MOV A,B
			OUT 02H
			JMP INPUT
DECREMENT:
			MOV A,B
			CPI 000H
			JZ LOWESTSTATE
			DCR B
			MOV A,B
			OUT 02H
			JMP INPUT
FFSTATE:
			MVI A,0FFH
			OUT 02H
			JMP INPUT
LOWESTSTATE:
			MVI A,00H
			OUT 02H
			JMP INPUT

Hi.. I edited the previous program and this is the latest. I believe the problem last posted by Ian Rogers has already been fixed but when I simulated it using oshonsoft, it still decrements sometimes when the input is not 01,02,or 04. Do you have any idea how to fix it?
 
Last edited:
ETO seemed to be down yesterday.... I'll pop it into the sim at home later..

Tested it in oshonsoft

01h = reset to 0xff....
02h = increments...
04h = decrements...

Nothing wrong here... works as expected
 
Last edited:
Thank you sir. I was explaining it to a classmate when it failed. Maybe I pasted one of my wrong versions of this program on the simulator.

Thanks again. :)

m8
 
You can save nine bytes by eliminating JNZ IORD, JZ INCREMENT and JZ 0820H. The OUT A0H instruction should have the 0820H tag preceding it.
Both CPI instructions could take a long time to attain, and cause a false system freeze or loop activity. This is a good program, just needs clarity on each subroutine. The loops created by the OUT and JMP could only be stopped by resetting the CPU.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top