Assembly Language(Seek for advice)

Thread Starter

Eugene Yip

Joined Mar 18, 2018
23
Hi, this is my first post in AAC forum
I have a homework that i don't really know how to start with it, and i'm still new in assembly language.
Question
Write a program to find the largest element in a block of data. The length of the block is defined in location 2501H and the block itself begins in memory location 2502H. Store the largest value in memory locations 2500H. Assume that the numbers in the block are all 8-bit unsigned binary numbers.

can anyone give any advice how to start/important step that i should take note when solving this type of question?
Thank you
 

MrChips

Joined Oct 2, 2009
34,628
The secret to writing any kind of computer program is to have a plan (especially a plan on paper).
You have not told us what computer and what programming language you are supposed to be targeting. And this is not important at this stage.

Get a piece of paper and pencil and make a plan (called an algorithm). You can do this by drawing pictures (called a flow-chart) or by writing out steps (called pseudo-code).

Play an imaginary game.

Pretend you have a box filled with pieces of paper. On each piece of paper a random number is written on it. You are now going to take one piece of paper out of the box.

Write down your steps as you play the game. For example:

STEP 1 - Take one piece of paper from the box.

Now, decide if this number is larger than any of the previous numbers you have already chosen. Write out how you do this.

This is the concept of an algorithm. It is creating a plan first without worrying about computer code.
 

shteii01

Joined Feb 19, 2010
4,644
Sounds like a job for a for loop.
2501H holds the length of the block, number of elements. So 2502H holds Element 0, 2503H holds Element 1 and so on. Now that you know the number of elements, you know how many iterations your for loop needs to run. Inside the for loop you will have if or if-else statement to compare the elements.
 

jpanhalt

Joined Jan 18, 2008
11,087
Since you are told the values are all 8-bit ( or less), you could simply add 1 (or increment, depending on the chip) and check for carry or zero. Keep track of the loops, then when you get carry, subtract that a value to adjust for loop number to reconstruct the original.

Is finding the largest element sufficient, or do you also have to know its memory location in the block of data? Finding the location will also depend on the chip. Do you have to preserve the block of memory?
 

ericgibbs

Joined Jan 29, 2010
21,390
hi Eugene,
OK, I see that you are still studying the Command set for the 8085 MCU.
In that PDF I posted, is a block of pseudo code, ref attached image.
Use the method shown in post #3, and try to create your own pseudo code block, so that you understand the program flow.
Post your version.
E
ESP1 19-Mar-18 08.54.gif
 

Thread Starter

Eugene Yip

Joined Mar 18, 2018
23
Sounds like a job for a for loop.
2501H holds the length of the block, number of elements. So 2502H holds Element 0, 2503H holds Element 1 and so on. Now that you know the number of elements, you know how many iterations your for loop needs to run. Inside the for loop you will have if or if-else statement to compare the elements.
uhmm...for the loop part i understand,what do you mean by if else statement? Sorry i didn't learn that before for assembly language
 

ericgibbs

Joined Jan 29, 2010
21,390
Its is:
[clip]
A high-level programming language statement that compares two or more sets of data and tests the results.
If the results are true, the THEN instructions are taken; if not,
the ELSE instructions are taken.
 

jpanhalt

Joined Jan 18, 2008
11,087
About half way though the presentation is this example:
Write an assembly program to find a largest value between two number at memory location 3000h and 3001h and store to memory location 3002h
The difference between that example and what you need to do is simply the number of registers you need to compare. All you need to do is test the first pair, save the largest, then advance to the next register (not pair) and repeat. I believe that is what Eric is proposing. I am not familiar with the 8085 instruction set, but I suspect there are at least 2 ways to advance to the next regoster: write code to increment the address for the highest of the current register pair or use "indirect addressing," which does the same thing. Indirect addressing is described in your lecture too.
 

Thread Starter

Eugene Yip

Joined Mar 18, 2018
23
Since you are told the values are all 8-bit ( or less), you could simply add 1 (or increment, depending on the chip) and check for carry or zero. Keep track of the loops, then when you get carry, subtract that a value to adjust for loop number to reconstruct the original.

Is finding the largest element sufficient, or do you also have to know its memory location in the block of data? Finding the location will also depend on the chip. Do you have to preserve the block of memory?
Just need to find the largest element
Another question is, for the 8-bit unsigned binary in the block of data should i show in hex form or in binary form?
 

jpanhalt

Joined Jan 18, 2008
11,087
I almost always use the hex form, unless specific bits are of interest, e.g., setting or clearing a bit(s) to effect an action. I find the hex form easier to read for the total value. The hex form is also more compact on paper or your PC screen.
 

Thread Starter

Eugene Yip

Joined Mar 18, 2018
23
Its is:
[clip]
A high-level programming language statement that compares two or more sets of data and tests the results.
If the results are true, the THEN instructions are taken; if not,
the ELSE instructions are taken.
i understand the function of if else statement, does the command of if else statement same like C/C++ programming ?(i mean the way to write in program)
 

LesJones

Joined Jan 8, 2017
4,511
I do not know the 8085 instruction set but I think it unlikely that it will have "THEN" and "ELSE" instructions. To see which byte is the largest you will probably subtract one value from the other and then check if the carry bit is set in the status register. You will probably use an instruction like skip if the carry bit is set. Your first step will be to find the instruction set for the 8085. Then you can work out which instructions are best to do what you want.

Les.
 
Last edited:

absf

Joined Dec 29, 2010
1,968
This is not the best clue, and my 8085 knowledge is elementary and completely rusty. It should go something like this....

Code:
1. HL = START_ADDR
   C = NO OF BYTES

2. GET BYTE FROM [HL] IN ACC
   DECREMENT C
   IF C=0 THEN GOTO END
2A. TRANSFER ACC TO B FOR COMPARISON

3. GET NEXT BYTE FROM [HL+1] IN ACC AGAIN
   COMPARE ACC WITH B    ;USE CMP INSTRUCTION

4. A>B: SAVE ACC IN LARGEST NUMBER
   GOTO 3

5. B>A: SAVE B IN LARGEST NUMBER
   COPY B TO ACC
   GOTO 2A

6. A=0: GOTO 3

END
Hope it helps.

[EDIT] Which assemblers and simulators are you using.

Allen
 
Last edited:
Top