Convert instruction from 8085 processor to atmega328p

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In an 8085 processor, the main program calls
the subroutine SUB1 given below. When the
program returns to the main program after
executing SUB1, the value in the accumulator
is?

 

Address           OpcodeMnemonics
2000                 3E00
2002                 CD0520
2005                 3C
2006                C9

 

SUB1:MVI A,00H
CALL SUB2
SUB2: INR
RET

Raj

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Wow that is a dodgy piece of code! If we assume INR is "increment accumulator" (I don't know 8085) then A starts with 0. It calls to the increment so then A holds 1. Then the nasty bit - it falls through in the the increment so by the time it hits RET the second time A will contain 2. I just hope that SUB1 itself is being CALLd and not being jumped to but it will return with A=2

 

If the thread title is right and you need this in 328 code then the AVR is a bit different. It effectively has thirty two accumulators (though 16 are a bit easier to use than the other 16) so you could do this very same thing there simply replacing "A" with R16 to R31. In that case MVI will become LDI. So:

SUB1:LDI R16,0
CALL SUB2
SUB2: INC R16
RET

But maybe it's just as easy to write:

SUB1: LDI R16, 2
      RET

which achieves the same in a more obvious way with less code and less cycles.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Go  on, Cliff.   You must have used that sort of construction in every Z80, 6502, 6800, 8085, ... assembly program that you ever wrote.

 

The difference is that you would have used meaningful names for the labels. 

 

The real mystery is why is Raj666 using a 40-year old CPU?

Ok,  one ASM program is much the same as another in terms of high level logic.

And many of the tips and tricks used 40 years ago to save a few bytes of ROM or machine cycles are still relevant.

 

Personally,   I think that a young student should concentrate on high level languages.   Learn how to write clear, straightforward code that is easy to maintain

After all,  modern chips have MegaBytes of Flash ROM and plenty of processing speed.   And HLL Compilers produce code that is as good as a competent ASM programmer and often better than the average ASM programmer.

 

David.

Last Edited: Tue. Nov 14, 2017 - 04:09 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

It's a homework question. See #43...

 

http://www.academia.edu/8112212/...

'This forum helps those who help themselves.'

 

pragmatic  adjective dealing with things sensibly and realistically in a way that is based on practical rather than theoretical consideration.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

david.prentice wrote:
 I think that a young student should concentrate on high level languages.

I think Kartman had it in one Raj666's other threads:

 

Kartman wrote:
Programming is somewhat different to writing code. We can see that with Raj - all he is worried about is the 'code', not the method of solving a given programming task. The 'code' is the result of design, not the beginning and end.

 

http://www.avrfreaks.net/comment...

 

 

That seems to be the problem with most questions posted here: people are just jumping straight into code without first understanding the problem or having any kind of design for the solution.

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Opcode 3C is INR A.

 

So you load A with 0, then call the procedure to increment A to get 1, then fall into the procedure an increment A to get 2, then return to whatever called...

 

(Just sounded like a fun puzzle. I googled 8085 opcodes.)

 

Used to write for 8085 like 33 years ago.

274,207,281-1 The largest known Mersenne Prime

Measure twice, cry, go back to the hardware store

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OT: I'm reverse engineering a Tek308 data analyser that has a 8085 in it. Since I've never really liked 8080/85 mnemonics, I used a Z80 disasm to generate the asm. To my surprise, the 8080/85 didn't have relative jumps whereas the Z80 did.

 

Besides, wouldn't one normally do a xor a (in Z80 mnemonics) to clear A and the flags? (obviously this is secondary to the actual question).

 

In trying to help himself, Raj is most likely doing himself and his countrymen a disservice by suggesting that to pass his engineering tests he has to cheat. What sort of image does that broadcast to the greater world? At what point in his career does he actually learn and be able to operate independently?