Define looping in assembly language, Computer Engineering

Assignment Help:

Q. Define looping in assembly language?

LOOPING 

; Program: Assume a constant inflation factor that is added to a series of prices

; stored in the memory. The program copies the new price over the old price. It is 

; assumed that price data is available in BCD form.

; The algorithm:

; Repeat

; Read a price from the array

; Add inflation factor

; Adjust result to correct BCD

; Put result back in array

; Until all prices are inflated

; REGISTERS: Uses DS, CS, AX, BX, CX

; PORTS        : Not used

ARRAYS                   SEGMENT

                                    PRICE                        DB 36h, 55h, 27h, 42h, 38h, 41h, 29h, 39h

ARRAYS                   ENDS

CODE                         SEGMENT

                                    ASSUME CS:CODE, DS: ARRAYS

START:                       MOV AX, ARRAYS; Initialize data segment

                                    MOV DS, AX; register using AX

                                    LEA BX, PRICES; initialize pointer to base of array

                                    MOV CX, 0008h; Initialise counter to 8 as array have 8

; Values.

DO_NEXT:                MOV AL, [BX]                      ; Copy a price to AL. BX is addressed in 

; Indirect mode.

                                    ADD AL, 0Ah                        ; Add inflation factor

                                    DAA                                                   ; Make sure that result is BCD

                                    MOV [BX], AL                      ; Copy result back to the memory 

                                    INC BX                                  ; increment BX to make it point to next price 

                                    DEC CX                                 ; Decrement counter register

                                    JNZ DO_NEXT                     : If not last, (last would be when CX will 

; become 0) Loop back to DO_NEXT

                                    MOV AH, 4CH                      ; Return to DOS

                                    INT 21H

CODE ENDS  

END START

Discussion: 

Please note the use of instruction: LEA BX, PRICES: It would load BX register with offset of the array PRICES in data segment. [BX] is an indirection through BX and comprises the value stored at that element of array. PRICES. BX is incremented to point to next element of array. CX register acts as a loop counter and is decremented by one to keep a check of the bounds of array. As soon as CX register becomes zero, zero flag is set to 1. JNZ instruction keeps track of value of CX and loop terminates when zero flag is 1 as JNZ doesn't loop back. The same program can be written by LOOP instruction in such case DEC CX and JNZ DO_NEXT instructions are substituted by LOOP DO_NEXT instruction. LOOP decrements value of CX and jumps to given label only if CX isn't equal to zero.


Related Discussions:- Define looping in assembly language

How can we minimize problems occurring because of branch., Q. How can we mi...

Q. How can we minimize problems occurring because of the branch instructions? We may use various mechanisms which may minimize the effect of branch penalty. To keep mult

Explain how presentation layer helps in establishing, Explain how presentat...

Explain how presentation layer helps in establishing and processing data in End to End layers. The idea of the presentation layer is to stand for information to the communicati

What is the principle of locality, What is "the principle of locality"? ...

What is "the principle of locality"? It's the nature of the processes that they refer only to the small subset of the total data space of the process. I.e. the process frequ

Explain call completion rate in telephone traffic, With reference to teleph...

With reference to telephone traffic, explain the terms CCR. CCR: Call completion rate is explained as the ratio of the number of successful calls to the number of call attemp

Describe the assume - assembler directives, Describe the Assume - Assembler...

Describe the Assume - Assembler directives ASSUME: This directive would be used to map the segment register names with memory addresses.  Syntax is as below: ASSUME SS:

Cryptography, Basically I need implement program using LC3 assembly languag...

Basically I need implement program using LC3 assembly language where I can type any message using ASCII code (this will my input). Then read the output in cipher text. It has to be

Illustrate the list of key differences to word processors, Illustrate the l...

Illustrate the list of key differences to word processors The following is a list of key differences to word processors: -  Most word processors force users to work on a doc

Difference between static and dynamic ram, Static RAM: No refreshing, 6 to ...

Static RAM: No refreshing, 6 to 8 MOS transistors are needed to form one memory cell, Information stored as voltage level in a flip flop. Dynamic RAM: Refreshed periodically, 3

Describe the concept of value creation, I am required to write about the im...

I am required to write about the impact of the internet on firms with reference to the following questions: 1. Describe the concept of value creation. Explain how a firm can use

Differences between flexgrid control and dbgrid control, Normal 0 ...

Normal 0 false false false EN-IN X-NONE X-NONE MicrosoftInternetExplorer4

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