Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Assembly Expert

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.

Assembly, Programming

  • Category:- Assembly
  • Reference No.:- M9521110

Have any Question?


Related Questions in Assembly

Task 1using masm sdk write an assembly language program

TASK 1 Using MASM SDK, write an assembly language program which converts an integer inputted via the console to binary. Your program should be well commented and well formatted. TASK 2 Using MASM SDK, write an assembly l ...

Really need to find a correct answer to this questionwrite

Really need to find a correct answer to this question: Write a MIPS assembly program that can search for a number that is entered by a user in an array with 20 integer number. Make sure it also prints the index of the ar ...

Question a sequence string of one-byte ascii characters is

Question : A sequence (string) of one-byte ASCII characters is stored at memory location $600 onward. A second sequence of equal length is stored at memory location $700 onward. Each sequence ends with the character $0 ( ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As