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

Explain cgi standard, Explain CGI standard. The CGI Standard: Techno...

Explain CGI standard. The CGI Standard: Technology utilized for building dynamic web documents is termed as Common Gateway Interface (CGI). The CGI standard gives how a serv

Selection - artificial intelligence, Selection - artificial intelligence: ...

Selection - artificial intelligence: However the first step is to choose the individuals that will have a shot at becoming the parents of the next generation. Hence this is kn

Explain language processing, System Software 1. Explain language proces...

System Software 1. Explain language processing? Explain its activities in detail. 2. Discuss briefly about Assembler directives. Also explain about Macro definition and call

Define http, Http Hyper Text Transfer Protocol: The WWW protocol that...

Http Hyper Text Transfer Protocol: The WWW protocol that performs the request and regain functions of a server. Generally seen as the first part of a website address. It is t

Determine what is the frame rate and frame duration, (i)  A multiplexer com...

(i)  A multiplexer combines four 100-Kbps channels using a time slot of 4 bits. Each Frame has the size of 16 bits. a)  Show the output with the four inputs as shown in the figu

Explain the use of functions in parallel programming, Q. Explain the Use of...

Q. Explain the Use of functions in parallel programming? include "pvm3.h" main() {    int cc, tid, msgtag;    char buf[100];    printf("%x\n", pvm_mytid());

Define end directive and assume directive, END DIRECTIVE: ENDS directive e...

END DIRECTIVE: ENDS directive ends a segment and ENDP directive ends a procedure and END directive ends whole program which appears as last statement. ASSUME Directive:   An .

Trace the pseudo-code, Consider the following pseudo-code segment. 1.  i...

Consider the following pseudo-code segment. 1.  input y {y is a three-digit hexadecimal number} 2.  d ← 0 3. for i = 1 to 3      3.1. char ← i th character from y readin

Functions for mpi environment, Q. Functions for MPI Environment? Int M...

Q. Functions for MPI Environment? Int MPI_Finalize (void) It ends the MPI environment. Any MPI function cannot be called after MPI_Finalize. Each MPI process belongs to on

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