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

Physics, derive an expression for vandar wall equation of state?

derive an expression for vandar wall equation of state?

Is the basic list deleted when the new list is created, Is the basic list d...

Is the basic list deleted when the new list is created? No.  It is not removed and you can return back to it using one of the standard navigation functions like clicking on th

Example of the horizon problem, Example of the horizon problem: It is ...

Example of the horizon problem: It is also worth bearing in mind the horizon problem, however a game-playing agent cannot see much far satisfactory into the search space. Now

Can we use flow logic control key words in abap/4, Can we use flow logic co...

Can we use flow logic control key words in ABAP/4 and vice-versa The flow control  of a dynpro having os a few statements that syntactically ressemble ABAP/4  statements .Thou

How to add cell padding, Q. How to Add Cell Padding? As you can see, te...

Q. How to Add Cell Padding? As you can see, text is too close to the edges of the cells. You will add padding to the cells to leave room between text and cells. 1.  Click in

What are the differences between struts and units, What are the differences...

What are the differences between struts and units?  A warm up question. Units are static objects that exist from the start of the simulation right up to its end, whereas struts

Explain the fixed logic versus programmable logic, Explain the Fixed Logic ...

Explain the Fixed Logic Versus Programmable Logic? The Logic devices can be classified into two broad categories - fixed and programmable. The same as the name suggests, the ci

Determine the o/p for JK flip flop with J=1 & K=0, For JK flip flop with J=...

For JK flip flop with J=1, K=0, the output after clock pulse will be ? Ans. The output will be 1 after clock pulse.

What is parallel loop construct, Q. What is Parallel Loop Construct? Pa...

Q. What is Parallel Loop Construct? Parallel loop construct is a shortcut for specifying parallel construct comprising one loop construct and no other statements. The syntax of

Is it possible to change the color and font of the sheet tab, Yes we can mo...

Yes we can modify the color of sheet tabs. By right clicking on sheet tabs and you will get option change color but you didn't find any option to modify the font of sheet tabs.

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