Assembly code microprocessor 8088 for seven segment LED

In summary: I don't.)In summary, the student is trying to program a 7 segment LED to display numbers in increments of 1, but is having difficulty doing so. He has tried different numbers, but none of them work. He asks for help, and the code provided by the tutor is for a 16-bit processor and does not work with the 8088. He eventually finds a way to program the LED using two loops and a call to the operating system.
  • #1
nsc
4
0

Homework Statement


i've just started learning microprocessors, and we need to program the 7-segment LED to display numbers 0-9 in increments of 1
i'm trying to get a delay of 1second between each number (and i couldn't get it)
e.g., number 1 displays for 1 second, then number 2 displays for 1 second

Homework Equations


i kept trying to change the number "9999" into bigger numbers n smaller for [MOV CX,9999]
but can't, so help please!


The Attempt at a Solution


attempt:

START:
MOV DX,0FF13H ;set 8255 mode 0
MOV AL,89H ;set port A mode 0 is output
OUT DX,AL ;set port c mode 0 is input
MOV DX,0FF10H ;output data from port A
MOV AL,00H ;copy data 01h to register AL
J1 : OUT DX,AL ;output data to port A
MOV CX,9999 ;
L1 : LOOP L1 ;time delay
INC AL
DAA
JMP J1 ;jump to label L1
 
Physics news on Phys.org
  • #2
I formatted your code using [ code] and [ /code] (without the leading spaces) tags.
nsc said:

Homework Statement


i've just started learning microprocessors, and we need to program the 7-segment LED to display numbers 0-9 in increments of 1
i'm trying to get a delay of 1second between each number (and i couldn't get it)
e.g., number 1 displays for 1 second, then number 2 displays for 1 second

Homework Equations


i kept trying to change the number "9999" into bigger numbers n smaller for [MOV CX,9999]
but can't, so help please!


The Attempt at a Solution


attempt:
Code:
START:	
	MOV	DX,0FF13H	;set 8255 mode 0
	MOV	AL,89H	;set port A mode 0 is output
	OUT	DX,AL		;set port c mode 0 is input
	MOV	DX,0FF10H	;output data from port A
	MOV	AL,00H		;copy data 01h to register AL
J1 :	OUT	DX,AL		;output data to port A
	MOV	CX,9999	;
L1 :	LOOP	L1		;time delay
	INC	AL
	DAA
	JMP	J1		;jump to label L1
Some of your comments are misleading or just plain wrong, which makes them unhelpful. It's very important to have good comments in assembly code, since assembly code is so arcane for people not used to it. For example, the MOV AL, 89H is apparently setting the mode of port A to input, yet the following line says "set port c mode 0 is input. In another line the instruction is MOV AL, 00h, but the comment says it is copying 01h to AL. The comments need to accurately reflect what the code is doing. If they don't, they might as well not be there.

I don't understand what you said here -
nsc said:
i kept trying to change the number "9999" into bigger numbers n smaller for [MOV CX,9999]
but can't, so help please!
What does that mean?

If you need a longer time interval, you can put a larger number in CX. It's a 16-bit register, so can hold a signed value as large as 32767.
 
  • #3
the codes were originally given by the lab tutor for racing LED lights, and for the 7segment we only executed a binary code file. so the task is to create the assembly code for the 7-seg display

i noticed something wrong with the comments too like "time delay" is on the wrong line... i don't want to change them because honestly, i don't really understand the codes yet... guess i should have erased it.

at first, the tutor said to change the code to CX, 0001H to have a 1s delay
but the number just doesn't change...

anyway, i tried larger numbers but as the delay become longer as i enter a larger number (up to 40000), the delay became shorter at even larger numbers like >60000

must the numbers between 1-32767?

*thanks for editing the code, its my 1st post although i always look around the forums
 
  • #4
Yes, since 8088 is a 16-bit processor, the initial value of CX should be either up to 32767 or up to 65535 (depends on the implementation of LOOP - you'd have to check the documentation; since your test indicates that larger numbers result in shorter delays, 32767 is probably the limit.)

8088's have clock frequencies of multiple MHz, so, each pass through your "L1" loop takes less than a microsecond. You will need to do two nested loops or to make a call to the operating system.
 
  • #5
Designing a timing loop is done by adding up the clock cycles needed to run the loop's body. One cycle needs 1/processor frequency.
For decent processors the manufacturer states the cycles needed to execute each instructions. For 8088 I found it incredibly hard to find a decent reference, but this page has cycles up from 286:
http://home.comcast.net/~fbui/intel.html

I would design the loop for 286 cycles (or invest more effort to find reference for 8088), this will give you a good estimate. After that you can measure the length of time your 0-9 show runs, and adjust accordingly if needed.

I have found one way to understand assembly: read the reference manual carefully.
(I am sorry for you having to learn assembly with that crap processor from the previous millenia. I would teach atmega if I would teach assembly.)
 
Last edited by a moderator:
  • #6
magwas said:
(I am sorry for you having to learn assembly with that crap processor from the previous millenia.
The 8088 was around only for the previous millennium, and at the very tail end at that.:biggrin:
 
  • #7
thanks for all the replies, they helped me in writing the report...which i already passed up.
anyway, i would still like to know how to do the code properly... i tried the looping, but 5 loops is needed for only a 1s delay. tested it and it worked. i want to know if there's any other way to do the delay? like a simpler way? what if i need to have a 1minute delay? that's a lot of loops!

Code:
;LED
JMP	START

START:	
	MOV	DX,0FF13H
	MOV	AL, 89H
	OUT	DX, AL
	MOV	DX, 0FF10H
	MOV	AL, 00H

J1:	
	OUT	DX, AL
	MOV	CX, 6000H

L1:	LOOP	L1
L2:	LOOP	L2
L3:	LOOP	L3
L4:	LOOP	L4
L5:	LOOP	L5

	INC	AL
	DAA
	JMP	J1
 
  • #8
You can nest the loops, and thus you need only two.
Decent processors have timer/counter units. You just tell the unit to generate an interrupt in say 1 second, and go ahed to do something meaningful.
However it is good to know how to do this type of timing. There are cases when the time delay needed is
too short to give away to timer, or you run out of resources.
 
  • #9
Your first loop (at label L1) will iterate for 6000H times, but the other loops are going to just fall through.

Just before your first loop starts, you're setting the CX register to 6000H. Each time the LOOP instruction executes it decrements CX, then executes the same LOOP instruction. When CX gets down to 0, control flows to the next instruction at label L2. However, CX is still 0, so control flows to the next instruction at label L3. And so on.

Try this instead:
Code:
	MOV	CX, 6000H
L1:	LOOP	L1

	MOV	CX, 6000H
L2:	LOOP	L2

	MOV	CX, 6000H
L3:	LOOP	L3

	MOV	CX, 6000H
L4:	LOOP	L4

	MOV	CX, 6000H
L5:	LOOP	L5
That should give you around a 5-sec. delay. Another way to do things is to put a loop inside of a loop (nested loop) rather than the sequential loops you are using.
 
  • #10
thanks, now i get what u said about the loop and the decrement. but, i tried the code on the 8088 and i don't get why the delay seem to shorten instead.

can you also show me how you would do the nested loops?
 
  • #11
nsc said:
thanks, now i get what u said about the loop and the decrement. but, i tried the code on the 8088 and i don't get why the delay seem to shorten instead.
Can you be clearer? What code did you try that made the loop shorten?
nsc said:
can you also show me how you would do the nested loops?
I think this will work.
Code:
	MOV	CX, 200H
L1:	...                        ; beginning of outer loop
             ...
             ...
             PUSH     CX
             MOV      CX, 30H

L2:         ...           ; beginning of inner (nested) loop
             ...
             ...
         
	LOOP	L2   ; end of inner loop

             POP       CX
             LOOP     L1   ; end of outer loop
The reason for the PUSH and POP instructions is that we're using the CX register for two different loop counters. So, just before the start of the inner loop, we save the current value of CX by pushing it onto the stack. Then we put a new value into CX for the inner loop.

Each time the outer loop runs, the inner loop runs 30H times. Since the outer loop runs 200H times, every instruction in the inner loop runs 6000H times.
 

1. What is assembly code and how does it relate to microprocessors?

Assembly code is a low-level programming language that uses mnemonic codes to represent machine instructions. It is specific to a particular microprocessor and allows direct control over the hardware. In the case of an 8088 microprocessor, assembly code would be used to manipulate the data and instructions that are processed by the CPU.

2. Can you explain the purpose of using assembly code for a seven segment LED display?

The seven segment LED display is a commonly used output device that can display numbers and some letters. Assembly code is used to control the display by sending specific instructions to the microprocessor, which then translates them into signals that turn on or off the individual segments, creating the desired characters.

3. How does the 8088 microprocessor handle instructions for the seven segment LED display?

The 8088 microprocessor has specific registers, such as the accumulator and the program counter, that are used to store and manipulate data and instructions. Assembly code is written to access these registers and send the necessary signals to the seven segment display to control what is being shown.

4. Are there any limitations to using assembly code for a seven segment LED display?

One limitation of using assembly code for a seven segment LED display is that it requires a good understanding of the specific microprocessor's architecture and instruction set. It can also be time-consuming and tedious to write and debug assembly code compared to other higher-level languages.

5. Can assembly code be used for other types of microprocessors and display devices?

Yes, assembly code is specific to a particular microprocessor and can be used for a variety of display devices, such as LCD screens, LEDs, and OLEDs. However, the assembly code will need to be modified accordingly to work with the specific hardware and its corresponding instruction set.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
20
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
9K
  • Programming and Computer Science
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
12
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
11K
  • Programming and Computer Science
Replies
7
Views
6K
Back
Top