Assembly 8085

Hi eneryone,
Im trying to learn about assemply 8085 in order to make a project i have.

First of all which emulator to use? I work in linux and I currently istalled GNUSim8085.
Also, maybe somewhere I can find some simple examples?

The project is about making an array saved in specific places in the memory with specific number in it. So i started with learning the loop for. I tried, with my little MIPS experience to assemply this C code:

int B = 0;
int A = 0;
for( A=0; A<5 ; A++ )
	B = B + 1;

my effort is this code:

;for

	MOV	#^00,B
for	MOV	#^00,A

loop	CMP	#^05,A
	BEQ	end_for

	ADD	#^01,B
	ADD	#^01,A
	JMP	loop
end_for	HLT

But i get errors in line 3. Anyway if anyone can help me please do so. I'm willing to learn and search with some help. Thanks.

Ps: What about gcc -S example.c ? What type of code i get in example.s?

You get what errors in line 3?

Yes, sorry..
I get:
unfinished code in line 3.

:wall:

	MVI	A,0
	MOV	A,B

loop	CMP	05,A
	BEQ	end_for

	ADD	01,B
	ADD	01,A
	JMP	loop
end_for	HLT

I think this must be better..
Error in line 4: Invalid command.

I found something with some help...
This:

        MVI A,00 
        MVI C,0AH 
        LXI D,0100H 
LOOP:   STAX D 
        INX D 
        INR A 
        DCR C 
        JNZ LOOP 
        HLT

makes this code:

for( i=0;i<10;i++ ) 
{ 
   a=i; 
} 

and the array is saved in memory at 0100H - 0109H.

That's the first part completed. Now i have to do the equation n=i^2-1 (i from the for loop) in order to save n in every row of my array.
Any help appreciated!

---------- Post updated 15-05-12 at 07:33 AM ---------- Previous update was 14-05-12 at 05:02 PM ----------

A first idea is to add i with itself at a loop and then decrease the result with dcr.
But i have problems with the coding part.. Anyone ?

As the 8085 doesnt have a multiply instruction you will have to add i to itself i times every time you go throgh the loop...here is a sample routine when i==3...

        MVI B,03H
	MVI A,0H
	MOV D,B
I2:	ADD B
	DCR D
	JNZ I2
	SUB 01H
	RET
1 Like

With Virtual 8085 I get 2 errors.
line 2: only 8-bit second operand.
I changed that with:

MVI A,00H

line 7: Invalid register specified.

Ok, i think that do the job!

	MVI B,03H
	MVI A,00H
	MOV D,B
I2:	ADD B
	DCR D
	JNZ I2
	DCR A
	MOV B,A
	STA 0001h
	HLT

Thanks for your help !

One last question on this.. Kind of stuck in that:
What is the routine, if my equation is n = 1 - i^2 ?
I'm a little new handling minus numbers in hex.
Maybe, something with MSB bit which is the sign (+/-) when we have a minus number?
:wall:

The 8085 uses 2s complement to represent negative numbers...so knowing that negate i^2 by inverting it and adding 1 to it followed by adding 1 again to represent the equation "n=1-i^2"...and in the final step display the result by taking the 2s complement of n.

1 Like