Zero flag, Assembly Language

Assignment Help:

Zero flag:

The next line compares the value in register. A with the value 1. If they are equivalent, the Zero flag is set (to 1). The next line then jumps to start: only if the Zero flag is not set, i.e.: the value in reg. A is not 1 therefore the switch was not pressed. Therefore the program will keep looping until the switch is pressed.

If the switch is pressed then the penultimate line writes down the value 1 to the accumulator, thus bit 0 = 1, and the LED comes on.

The last line jumps back to start. It completes the loop of reading the switch and writing to the LED.

This specific problem could have been solved out with just a switch connected to an LED, as a light is linked to a wall switch in your house. But along with a microprocessor in the loop, much more could be done. We could have a clock that also turns on and off the LED depend on time. Or we could monitor the temperature and turn the LED on and off depend on what temperature it is. Or we could monitor various switches and turn the LED on and off depend on a combination of switches, etc. This is up to the imagination what may be controlled.

In the above instance we supposed that the other bits of ports 0 and 1 were all zeros. But in realism, each bit could have a function assigned to them. Then we would have to look only at bit 0 in port 0 and bit 0 in port 1. It further complicates the problem. Also, we suppose that port 0 was previously described as an input port whereas port 1 was defined as an output port.

In assembly we can assign a name to a port and refer to it by that name, rather than port 0 or port 1. It is done with an equate directive. Directives are assembler commands which don't result in program but instead instruct the assembler to some action. All of the directives start with a period.

.equ switch, 0  ;port 0 is now called switch

.equ LED,1       ;port 1 is now called LED

start :   IN         switch  ; read Port 0 into reg. A

CMP    1          ; compare reg. A with the value 1

JNZ      start     ; jump to start if the comparison does not yield 0

OUT     LED      ; send a 1 to Port 1, turning the LED on

JMP     start

It has the same result as the earlier program. Also equate only need to be made once at the start of the program, and thereafter the name or label is utilized instead of the port number. It makes things much simpler for the programmer. All equates should be defined before they are used in a program. It holds true for labels also. Another advantage of naming ports with equate is that if, later on in the design process, you decide to utilizes a different port for the LED or the switch, only the equate has to be changed, not the program itself.

Please note down that comments are extremely important. While you initially write a program, the tendency is not to write much in the comment field because you're in a hurry. But if you need to come back to it a few weeks later, it is much simple to understand what you've written if you've taken the time to write down good comments. Also good comments help out in debugging process.


Related Discussions:- Zero flag

Pin functions of 8086-microprocessor, Pin functions for the minimum mode o...

Pin functions for the minimum mode operation of 8086 are following: 1) M/I/O -Memory/IO: This is a status line logically equivalent to S2 in maximum mode. When it is low, it

Aas-arithmetic instruction-microprocessor, AAS: ASCII Adjust AL After Subt...

AAS: ASCII Adjust AL After Subtraction AAS instruction correct the result in the AL register after subtracting operation of two unpacked ASCII operands. The result is in unpacked

Port mapped or mapped input output, Port Mapped I/O or I/O Mapped I/O I...

Port Mapped I/O or I/O Mapped I/O I/O devices are mapped into a separate address space. This is generally accomplished by having a different set of signal lines to denote a mem

Program for declare the threshold, 1. Start your program at address $8500. ...

1. Start your program at address $8500. To do this you need to inform the assembler, through the EQU and ORG assembler directives, that you want your program to start at $8500. Thi

Intel 8259 interrupt controller-microprocessor, Intel 8259 interrupt contro...

Intel 8259 interrupt controller :  The 8088 processor has only two interrupt control inputs, and interrupt request (INTR) and non mask able interrupt (NMI). NMI are interrupts t

8086 assembly language, write and run a programme using 8086 assembly langu...

write and run a programme using 8086 assembly language that interchange the lower four bits of AL registered with upper four bits.

Program, move a byte string ,16 bytes long from the offset 0200H to 0300H i...

move a byte string ,16 bytes long from the offset 0200H to 0300H in the segment 7000H..

Project, need some project ideas

need some project ideas

Prepare the assembly code sequence, Problem (a) Prepare the assembly c...

Problem (a) Prepare the assembly code sequence for each of the four styles (accumulator, memory-memory, stack, load/store) of machine for the code fragment: A = B + C;

Code, How to print strings in Right Triangle form?

How to print strings in Right Triangle form?

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd