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

Complicated question, Hi I need a help in this question : A telephone sw...

Hi I need a help in this question : A telephone switchboard handles ? calls on average during a rush hour, and the switchboard can at most make k connections per minute. Write a

Illustrate working of rubber dome keyboards, Q. Illustrate working of rubbe...

Q. Illustrate working of rubber dome keyboards? Rubber Dome: In rubber dome keyboards both positioning and contact are controlled by a puckered sheet of elastomer that is a s

Describe about the forms-DBMS, Describe about the Forms- DBMS Forms ar...

Describe about the Forms- DBMS Forms are generally known as data entry screens as they are user interface that allows data in the tables to be viewed, edited or entered. Forms

Compute the positive integer and square root, Question: Q1) Write a cod...

Question: Q1) Write a code that asks the user for a positive integer, computes the square root of that integer, and return the result to the user. The computational error needs

What do you mean by file, Q. What do you mean by File? In computer voca...

Q. What do you mean by File? In computer vocabulary, file is a collection of text or data stored on a storage device, such as a Floppy Disk or Hard Disk. If you a fresher to c

Difference between vertical and horizontal organization, Difference between...

Difference between Vertical and Horizontal Organization Vertical Organizations  It is a usual approach which is typified by a functional approach to work in which departme

What are the largest UDP messages, What are the largest UDP messages that c...

What are the largest UDP messages that can fit into single Ethernet frame? UDP utilizes IP for delivery. As ICMP UDP packet is encapsulated in IP datagram. Therefore entire UDP

Adaptive mechanism in Ais, pls give the list of adaptive mechanism in arti...

pls give the list of adaptive mechanism in artificial immune system

Time slice, The Linux Process Scheduler uses time slice to prevent a single...

The Linux Process Scheduler uses time slice to prevent a single process from using the CPU for too long. A time slice specifies how long the process can use the CPU. In our simulat

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