This is default featured slide 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

Showing posts with label 8086 microprocessor Programming. Show all posts
Showing posts with label 8086 microprocessor Programming. Show all posts

Friday, 25 January 2013

8086 microprocessor Programming (Part 8)

ADJUSTMENT INSTRUCTION

OBJECTIVES:


  • To study the 8086 instruction for ASCII and decimal adjustment for addition and subtraction.
  • To study the 8086 instruction for adjustment of multiplication and division of unpacked BCD numbers


INSTRUCTION:

ASCII and Packed Decimal Arithmetic:
When ASCII digits are added, the AAA( ASCII adjust after addition) instruction converts the binary result to BCD format. AAS performs the same operations after subtraction and AAM is used after multiplication. AAD (ASCII adjust before division) modifies AX before division takes place. All of this instruction is valid only for 8-bit operations.
Two instructions adjust the result of packed decimal operation. The DAA (decimal adjust after addition)  instruction adjust the contents of AL after 8-bit addition or subtraction, respectively

EXPERIMENT:


There are four parts of this experiment, each containing a relatively  smaller program. It will be convenient for you to put the main body of the program in the program template defined earlier in experiment 4. This will help you save time writing four times the common MASM directives and initialization instructions.

Part-1 : 

The following program is taken from chapter 8 of [1]. Writes it in a text editor, assemble, and link it, and then load it in DEBUG. Trace the program, and note down the contents of AL before and after the execution of AAA instruction, each time it is executed. Try the program for some other values of two input operands.

Page, 132
Title ASCII Decimal Addition
dosseg
.model small
.stack 100h
numdigits equ   8 ; number of digit
.code
comment # Demonstration of ASCII addition using two 8-digit strings
The AAA instruction adjusts the result after each addition#.
main   proc
mov ax @data ; initialize the DS register
mov ds,ax
mov   cx, numdigits ; set loop counter
mov  si, numdigits¬_1 ; point SI to first digit
mov ax, 0 ; initialize AX
next_digit :
mov al, val1[si] ; get digit from val1
add al, ah ; add previous carry
mov ah,0
add al, val2[si] ; add digit from val2
aaa ; AX= adjusted result
; AH contains carry if an y
or  al,30h ; convert digit to ASCII
mov result[si], al ; store digit in result
dec  si
dec cx
jnz next_digit ; back up the index
mov ax, 4C00h
int 21 h
main endp
.data
val1 db ‘09999999’ ; input operand
val2 db ‘09999999’ ; input operand
result db  numdigits dup(0)    ; result ‘19999998’
end main

Note : We have used a new assembler directive and a new member operator in the       program They are
1. EQU Directive: It assigns a symbolic name to a string or numeric constant. This increase the readability of a program and makes it possible to change constant in a single place at the beginning of a program .
2. DUP Operator: It repeats a single- or multiple byte value. For example, 20 bytes containing all binary  zeros would be coded as : db 20 dup ( 0)

Part –II:

The following program adds two 9-byte packed BCD numbers. Refer to chapter 8 of [1]. Trace it with DEBUG and note down the contents of AL both before and after the DAA instruction, each time it is executed check the AC and C flages as well.
Page, 132
title packed decimal addition
dosseg
.model small
.stack 100 h
.code
numbytes  equ   9 ; number of bytes to be added
main proc
mov ax. @data ; initialize the DS register
mov dx,ax
mov cx, numbytes ;
mov si, numbytes_1 ; start at lowest digit
clc ; clear carry flag
next_digit:
mov al, val1 [si] ; get digit from val1
adc al, val2 [si] ; add digit from val2 + carry
daa ; AL contains adjusted result
mov result [si] ; store the digit
dec si ; point to next byte
loop next_digit
mov ax, 4c00h
int   21h
main endp
data ; variables here
val1    db 09h,87h,65h,43h,87h46h,69h, 83h,76h
val2   db 00h,08h,76h,54h,32h,72h,84h,05h
result db numbytes dup (0)
end main

Note: The ‘loop’ instruction decrements CX register and jumps to a short label if CX is greater that zero. The short label must be in the range- 128 to + 127 bytes from the next instruction

Part-III:

The following program contains adjustment instruction for subtraction. Trace it in DEBUG, and note down the constants of AL and status flags where asked in the comments.
Page, 132
title Subtraction
dosseg
.model small
.stack 100 h
.code
main proc
mov ax,@data ; initgialize the DS register
mov ds, ax
mov al,38h ; ASCII for ‘8’
move bl,39h ; ASCII for ‘9’
sub al,bl ; note down
aas ; note down and comment
mov  al, 48h ; packed BCD 40
mov bl,85h ; packed BCD85
sub al,bl ; note down
das ; note down
mov ax,4C00h
int 21 h
main endp
.data ; variables here
end main

Part –IV:

The following program contains adjustment instructions for multiplication and division of unpacked BCD numbers. Write the program and load the ‘exe’file in DEBUG, Skip whenever you come across an ‘int 21h’instruction by setting appropriate breakpoint. Try for different input values

Page, 132.
title Multiplication and Division
dosseg
.model small
.stack 100h
.code
main proc
mov ax, @data ; initialize the DS register
mov da,ax
Comment # note down the constants of AX before and after the execution of AAM instruction #
mov   ah,01h ; inpute mode
int  21h ; get multiplicand in AL
and al, 0fh ; make it unpacked BCD
mov  bl,al ; save in BI
int     21h ; get multiplier
and al,ofh ; make it unpacked BCD
nul bl ; multiply the two numbers
aam ; ASCII adjust after
; multiplication
comment # Note down the contents of AX before and after the execution of AAD instruction # .
move ah,01h ; inpute mode
int  21 h ; get divisor in AL
and al ,0fh ; make it unpacked BCD
move bl,al ; save in BL
int 21 h ; get MS digit of dividend
and al,ofh ; make it unpacked BCD
move bh,al ; save in BH
int 21h ; get LS digit of dividend
move al,0fh ; make it unpacked BCD
mov  ah, bh ; now AX contains the dividend
; concerts to hex
aad ; adjustment before division

div bl
mov ax,4C00h
int 21h
main endp
.data ; variables here
end main

REFERENCES:


  1. Kip R. Irvine. Assembly Language for the IBM-PC Macmillan Publishing Company, 1990.


8086 microprocessor Programming (Part 7)


JUMP INSTRUCTIONS

OBJECTIVES

  • To become more familiar with the 8086 compare instruction.
  • To study the 8086 instructions for implementing conditional logic structures.


INTRODUCTION:

Here are no conditional logic structures in the 8086 assembly language. But we can implement almost any structure using a combination of statements. A logic structure is simply a group of conditional statements working together. The WHILE structure, for instance, has an implied IF statement at its beginning that evaluates a condition:

Structured Unstructured

DO WHILE; L1 IF (a>=b)THEN
<statement-1> jump to L2
<statement-2>   ENDIF
<statement-1>
ENDDO <statement-2>
:
jump to L1
L2: (continue here)
The angle brackets (<>) around the word statement identify a program statement. Two steps are involved in executing IF statement. First, an arithmetic or comparison instruction sets one or more flages based on its result. Second, a conditional jump instruction may cause the CPU to jump to a new address. The instructions used belong to one of two groups:

Group 1: Comparison and arithmetic instructions, in which the CPU sets individual flags according to the result.
Group 2: Conditional jump instructions, in which the CPU takes action based on the flags.

The instructions from the two groups work in tandem: An instruction from Group 1 is executed affecting the flags, then a conditional jump instruction from Group 2 executes, based on the value of one of the flags. In the following example the JZ instruction jumps to ‘next’ if AL = 0.
Cmp a1 , 0
Jz next
  next :               ;  label
Conditional Jump Instructions: A Conditional jump instruction, transfers control to a destination address when a flag condition is true. The syntax is:
J cond destination
Here cond refers to a flag condition, identifying the state of one or more flags. For example:

C Carry flag set
NC Carry flag not set (clear)
Z Zero flag set
NZ Zero flag not set (clear)

We have already seen that flags are set by arithmetic, comparison, and Boolean instructions. Each conditional jump instruction checks one or more flags returning a result of true or false. If the result is true the jump is taken; otherwise, the program does nothing and continues to the next instruction. Note that these instructions themselves do not affect any of the six status flags.

EXPERIMENT: Here are four parts of this experiment, each containing a relatively smaller program. It will be convenient for user to put the main body of the program in the program template defined earlier in experiment 4. This will help you save time writing four times the common MASM directives and initialization instructions.

PART-1: The following program is taken from chapter 7 of [1]. It converts each character type at the keyboard is uppercase. The program ends when ENTER is pressed. Write it in a text editor , assemble and link it and then run it from DOS prompt to verify.
Page, 132
Title  uppercase display program
dosseg
.model small
.stack 100h
carr_ret equ 0Dh ; ASCII code of carriage return code
main proc
label _ 1
mov ah. 08h ; input a character, no echo
int 21h
cmp al, carr_ret ; ENTER pressed?
Je label _ 3 ; yes: quit
cmp al, ‘a’ ; character < ‘a’?
Jb label _ 2 ; if below, display it
cmp al,   ‘z’ ; character > ‘z’ ?
ja label _ 2 ;  if above, display it
sub al , 20h ; no , subtract 20h from ASCII code
label _ 2
mov ah, 02h ; function display character
mov dl , al ; character is in Dl
int 21h ; call DOS interrupt
;  get another character
jmp label _ 1 ; unconditional jump
label _ 3
mov ; ax , 4c00h
int 21h
main endp
data ; variables here
end main
  1. What happens if you enter a character other than from a-z?
  2. If you want to make a program which converts an uppercase characters in to lower case, what changes will be required in the above program?
  3. Which flags are tested the execution of ‘je’ , ‘jb’ , and ‘ja’ instructions. Use DEBUG to find the answer.


Part – II: The following program is adopted from chapter 7 of [1]. It finds the largest and smallest signed numbers in an array of integers. The numbers input don’t have any suffix (e,g, h, b, or d). This means that they will be treated as decimal numbers. These numbers will be converted by the MASM in to proper hex numbers. A negative number will be converted in to its 2’s complement from by the MASM. Run the program in DEBUG.
page, 132
title Largest and Smallest Signed Numbers
dosseg
.model small
.stack 100h
.code
num_digits equ 6
main proc
mov ax . @data ; initialize the DS register
mov ds , ax
mov di , offset  array
mov ax , [di]
mov largest . ax ; initialize largest
mov smallest . ax ; initialize smallest
mov cx , num digits-1
label_1
add di , 2h ; point to next number
mov ax , [di] ; get next number
cmp ax , smallest ; [DI] >= smallest?
jge label_2 ; yes : skip
mov smallest , ax ;no:  move  [DI] to smallest
label_2:
cmp ax , largest ; [DI]  <=  largest?
jle label_3 ; yes : skip
mov largest . ax ; no:  move [DI] to largest
label_3:
loop  label_1 ; repeat until  CX =0
mov ax , 4C00h
int 21h
main endp
 data ; variable here
array dw -1 , 2000, 32767, 500,0
largest dw ?
smallest dw ?
end main
  1. Note down from DEBUG the hex equivalent of the above six numbers.
  2. Modify the program, so that it finds the largest and smallest of the following array of numbers: 200, -300, -7699, -3289, -2278, -9910, -5436, 98, 10.
  3. Why are the contents of CX registers initialized at num_digits – 1 and not num_digits?
  4. What is the range of integers over which this program works ? What happens if the array has a number out of this range.

Part –III:
  • write a program that sorts, in descending order, a given list of integers in the range of

-32, 768  to +32,767. First make a flow chart with the help of following algorithm:
Call the elements of the second number, A(0), A(1), A(2), …., A(n). Take the first number in array, which is A(0), and compare it with the second number, A(1),. If A(0) is greater than A(1), the two numbers are swapped otherwise they are left alone. Next A(0) is compared with A(2) and on the basis of the result of this comparison, they are either swapped or left alone. This sequence is repeated until A(0) has been compared with all numbers up through A(n). When this is complete, the smallest number will be in A(0) position. New A(1) must be compared with A(2) through A(n) in the same way . After this is done, the second smallest number will be in A(1) position. The same procedure is repeated for A(2) through A(n-1) to complete the soft.

REFERENCES:

  1. Kip R. Irvine. Assembly Language for the IBM-PC Macmillan Publishing Company, 1990.
  2. Avtar Singh and Walter A. Triebel, The 8086 and 80286 Microprocessors, Hardware, Software, and Interfacing. Prentice-Hall Inc, 1990.


8086 microprocessor Programming (Part 6)


8086 STATUS FLAGS


Aims of the Experiment: 

  • To study the effect of different instructions on the 8086 status flags. 
  • To introduce the students to the strategy for finding errors (debugging) in an assembly language program. 


Introduction: 

The 8086 microprocessor has nine flags. Out of these nine flags, six are called status flags. These flags indicate conditions that are produced as the result of executing an arithmetic or logic instruction. That is, specific flag bits are reset (logic 0) or set (logic 1) at the completion of execution of the instruction. These status flags are : the carry flag (CF), the parity flag (PF), the auxiliary carry flag (AC) , the zero flag (ZF), the sign flag (SF), and the overflow flag (OF). The remaining three (out of nine) flags are called the control flags, and they are : the trap flag (TF), the interrupt flag (IF), and the direction flag (DF).  

In the first part of this experiment, we’ll use DEBUG to study these flags (except TF). When you load a program in DEBUG, and then trace it, the contents of all the registers as well as the status of all but trace flag (TF) are displayed after the execution of each instruction. The flags are displayed in the order given below. The DEBUG syntax for set/reset condition of these flags is also included in the following table:

Flag Type
Syntax for Set (logic 1)
Syntax for Reset (logic 0)
Overflow
OV
NV
Direction
DN
UP
Interrupt
EI
DI
Sing
NG
PL
Zero
ZR
NZ
Auxiliary Carry
AC
NA
Parity
PE
PO
Carry
CY
NC

Following points are worth mentioning here:
  • None of the data transfer instructions (mov, xchg, xlat, lea, lds, and les) changes any of the status flags, that is, the status of these flags remains the same after the execution of these instructions as it was before the execution. 
  • The addition and subtraction instructions (add, adc, sub, sbb) affect all the six status flags. 


These flags are used in decision-making instructions like the ‘jnz’ and ‘jnc’ instructions that you are already familiar with. It is important to know before taking a decision based on these flags (for example using conditional jumps) whether the instruction you are using affects the flag used by the decision making instruction. It is a good  practice to consult a reference book to check if the instruction in use changes the status of a flag. 

Important Notes:

  • Write the following program in a text editor, assemble, and link it, and then load it in DEBUG. Trace the program, and answer on your work sheet the questions asked in comments. Answer only for the six status flags. 


Page, 132 
Title # Program for studying flags # 

Dosseg 
.model small 
.stack 100h
.code 
order-word proc 
mov ax, @data ;initialize the DS register 
mov ds, ax 
mov al, 53h 
sub al, 53h ;1. which flags are set and why?
mov   ah, 73h 
add ah,38h ; 2. Which flags are set and why?
mov cx, 9FF8h
add cx, 9CCCh ; 3. Which flags are set and why?
clc ; clear carry flag command. It 
; will be reset (logic 0).
mov dl, 0Feh ; 4. Check if any flags changed. 
Inc dl ; 5 . Which flags are set and why?
Inc dl ; 6. which flags are set and why?
stc ; set carry flag. Check if so.
mov ax, 2000h
adc ax, 0Fh ; add with carry command 
; 7. Which flags are set and why?
mov al , 08h 
mov cl, 1Fh
mul cl ; 8. Note CF and OF status 
; the following segment contains 8086 logic instructions 
mov al, 01010101b ; load binary number 
and al, 00011111b ; 9. What is result? Why? Note 
; OF, CF, PF , ZF, and SF 
or al, 11000000b ;10. What is result now?
Xor al, 00001111b ;11. What is result now?
not al ;12.What now? (1’s comp.) 

Comment# The following segment contains 8086 shift instructions 
;13 Note the status of carry flag after each of the following instructions are executed. Also note the contents of AL after each SHL instruction. You’ll notice that shifting left by one position is equivalent to multiplying by 2, and shift right by one position is same as dividing by 2. # 

mov al, 0aah
shl al,1 ;shift AL left one position
shl al,1
shl al,1
shl al,1
mov cl, 04ch ;shift AL left 4 times
shl al, cl

mov bx, 0888h
mov cl, 05
shr bx,cl ;note the contents of BX register

mov ax, 0888h
mov cl, 20h
div cl ; note the contents of AL
; they should be the same as of BX

Comment # The following program segment uses the 8086 rotate instructions. They are different from shift instructions in that the contents of carry flag are also involved in this movement.
1b. Note the contents of carry flag and the AX register after each of the following instructions is executed #

mov ax, 5555h
ror ax, 1 ; rotate right one position
ror ax, 1
ror ax, 1
ror ax, 1

mov cl, 06h ; rotate right six position
ror ax, cl

rol ax, cl ; rotate left by six 
rol ax, l ; rotate left by one position
rol ax, l
rol ax, l

mov ax, 4C00h
int 21h

order_word endp
.data
end order_word


  • In the last experiment there was a program for converting a string of binary numbers into a corresponding string of gray code numbers. There were some errors in the algorithm, because of which the program only converted the numbers between 0-7 (hex) correctly into gray code numbers. It returned garbage for the numbers between 8-F (hex). In the following program, we have improved the algorithm so that it should return the correct gray code string for a string of hex numbers 0-F (hex). There are, however two bugs deliberately placed in this program find out the bugs. Use DEBUG whenever you feel necessary. It will help you great deal if you make flow chart for this program.


Title program for converting binary string to gray code string.

Dosseg
.model small
.stack 100h
.code

order_word proc
mov ax, @data
mov ds, ax ;initialize data segment register
mov si, 1000h
mov dx, 08h ;initialize the counter
mov ah, 01h ;character with echo
next_word:
int21h
cmp al, 60h ;compare instructions
jc ab_cd ;from AL but Al remains unchanged
add al, 09h ;only flag is affected
ab_cd:
and al, 0fh
mov cl, al
call code_conv
cmp cl, 0ah
jc numeral
sub cl, 09h
or cl,60h
jmp alphabet
numeral:
or cl, 30h
alphabet:
mov [si], cl
inc si
dec dx
jnz next_word
mov si, 1000h
mov cx, 08h
mov ah, 02h
previous_word:
inc si
mov dl, [si]
int 21h
dec cx
jnz previous_word
mov ax, 4c00h
int 21h
order_word endp
code_conv proc
push ax
mov bx, offset values
mov al, cl
xlat
mov cl, al
pop ax
ret
code_conv endp

.data
values db 0h,1h,3h,2h,6h,7h,5h,0ch,0dh,0fh,0eh,0ah,9h,8h
end order_word


  • Try the program for finding mean square of eight decimal numbers (0-9), that you were asked to do in the bonus part of the last experiment.



8086 microprocessor Programming (Part 5)

PROGRAMMING (CONTINUED)


Aims of the Experiment:

  • To develop further understanding of arithmetic instructions.
  • Give a brief introduction to subroutine handling instructions. 
  • Give introduction to some simple DOS functions using ‘int 21h’. 


Important Notes:

  • DOS Function Requests:

The DOS operating system uses interrupt type 21h to make many functions available to the user. Most of these functions provide for input and/or output to devices. Many are for various operations with disk files. See Appendix C of [1] for details of these functions. In this experiment, we’ll discuss how to use DOS functions and describe some of the simpler ones. 
All functions called with ‘int 21h’ invoke the same interrupt handler. The desired function is selected by placing its function number in the AH register half. Many functions either require additional data to be sent to the interrupt handler procedure and/or they return information. Such parameters are normally passed using registers. The only registers altered by this interrupt handler are those used to return information to the user. The following table summarizes some of the functions covered in this experiment. 

Function Action Parameter (s) 
for DOS Parameter(s) DOS Returned by 
Number
1h Input character 
(with echo)   None Character in AL
2h Display character Character in
 DL None
8h Input character
 (no echo) None Character in Al
4Ch Terminate 
process Return code 
in AL None

 Each complete program in previous experiment used DOS function 4Ch to terminate program execution. (Remember we put 4C00h in AX before ‘int 21 h’ instruction.) We’ll use other functions in this experiment for input and output of characters from/to the console. 

  • You have been using DEBUG program. While using this program, it should be kept in mind that it works in default with hex numbers. The MASM/TASM program, on the other hand, works in default with decimal numbers. So, in order to work with hex numbers while using MASM/TASM , always put an ‘h’ followed by the number. For example ‘1234’ will be treated as decimal 1234, whereas ‘1234h’ will be treated as hex 1234. 

  • Whenever the first digit in a hex number is an alphabet (a-h), do not forget to put a ‘0’ before this number, otherwise an error will occur. As an example, instead of writing ‘F000h’ always write ‘0F000h’. 

  • Write the following program in a text editor. 

Page, 132
Title #. None # 
Dosseg 
.model samall 
.stack 100h 
.data ; variables here
.code 
order _word proc 
mov ax, @data ; initialize the DS register 
mov ds, ax 
mov si, 1000h
mov cx, 08h ; initialize the counter reg. 
mov ah,01h ; DOS function for input character with echo  
       next_word: ; this a label 
int 21h ; interrupt for DOS services 
mov [si] , al ; save the input byte 
inc si ; the next byte 
dec cx ; decrement counter 
               jnz next-word ; go back if count if count not zero 
               mov cx, 08h ; DOS function for display char 
              mov   ah, 02h
Previous_word:
dec si 
mov d1, [si] ; get char to be displayed in DL 
int 21h ; interrupt for DOS services 
dec cx 
jnz previous_word

mov ax, 4C00h ; end program 
int 21 h 
order_word endp 
end order_word 

Save assemble, and link this program and run it first at the DOS prompt. The program will wait for you to type eight characters on the keyboard. Answer the following questions: 

  1. What is this program doing?
  2. Why have we used the instruction ‘dec si’ before ‘int 21h’? What will happen if we place it after the ‘int 21h’ instruction? 
  3. Make a modification in this program so that it displays only the first, third, fifth, and seventh input characters in that order. Verify our program. 


  • The following program uses the Binary to Reflected Gray Code conversion subroutine of the last experiment to convert a string of binary numbers to a corresponding string of Gray Code numbers. Write the following assembly language program using a text editor: 

Page, 132
Title program for converting Binary String to Gray Code String 

Dosseg 
.model small 
.stack 100h 
        .data ; variables here 
values db 0h, 1h, 3h,2h, 6h, 7h, 5h, 4h, 0ch, 0dh, 0fh, 0eh, 0ah, 0bh, 9h, 8h.
.code
order_word proc
mov ax, @data ; initialize the DS register 
mov ds, ax 
mov si, 01000h
mov dx, 08h initialize the counter reg. 
mov ah, 01h ; DOS function for input  character, with echo 
next_word: this a label 
int 21 h ;nterrupt for DOS services 
mov cl, al ;opy AL in CL 
and cl, 0fh ;make the upper nibble ‘0’ 
;ince AL contains ASCII code 
and al, 0f0h ;save the upper nibble 
call code_conv 
or cl, al ;convert back to ASCII 
mov [si], cl ; save the input byte 
inc si ; the next byte 
dec dx ; decrement counter 
jnz next_word ; go back if cont not zero 
mov si , 1000h ; re-initialize SI 
mov cx, 08h 
mov ah, 02h ; DOS function for display char 
previous_word: 
mov d1, [si] ; get char to be displayed in DL 
int 21 h ; interrupt for DOS services 
inc si 
dec cx 
jnz previous_word 

mov ax, 4C00h ; end program 
int 21h 
order_word endp ; main procedure ends here 
code_conv proc ; Code conversion subroutine   
push ax ; save AX as it will be 
; used in this subroutine
mov bx, offset values ; offset directive to load 
; the offset ad. Of values in BX 
mov al, cl 
xlat ; replace AL by contents 
; of DS: BX + AL 
mov cl, al
pop ax ; Get back the orig. value of AX 
ret
code_conv endp 
end order_word 

Save the program, assemble and link it, and finally run it form the DOS prompt. Load in DEBUG and trace the program to understand the meanings of each instruction. 

Answer the following questions: 
  1. What will happen if you do not use the ‘AND’ and ‘OR’ instructions in the above program?   
  2. Using DEBUG, find out what are the contents of SS: SP before and after the execution of the ‘PUSH AX’ instruction. 


  • Convert the negative numbers in the following list in to 2’s complement form and replace ni (i=1 to 8) in the data segment of the following program by these numbers. Write this program, assemble, and link it. Find out the purpose of this program. Put comments where you feel necessary. To get more insight, trace with DEBUG. List of numbers: 0228h, -225Ah, 0524h, 25Afh, -023Bh, -1133h, 2FFABh, 1230h. 


Page, 132
Title program for Adding 8 data words 

Dosseg 
.model small 
.stack 100h
.data ; variables here 
value dw nl, n2,n3,n4, n5, n6, n7, n8
.code 
add_word proc 
mov ax, @data ; initialize the DS register 
mov ds, ax
mov si, 0h ; initialize source index 
mov ax, 0h ; initialize the sum register 
mov cx, 08h ; initialize the counter reg. 
mov dl, 0h 
next_word: 
add ax, [si+ offset value] 
jnc no_increment 
inc dl 
no_increment: 
inc si 
inc si 
dec cx 
jnz next_word 

mov [si+ offset value] , ax 
inc si 
inc si 
mov [si+ offset value] , dl 
mov ax, 4C00h ; end program 
int 21h 
add_word endp 
end add_word 

  • Write, assemble, and debug an assembly language program that asks the user to enter 8 decimal numbers (0-9), and then it finds the mean of these numbers and displays the result on screen. 
  • Try to modify the program such that it calculates the mean square value and then displays all the digits of the result on screen? 



REFERENCES: 

  1. Kip R. Irvine, Assembly Language for the IBM-PC. Macmillan Publishing Company, 1990. 
  2. Avtar Sing and Walter A. Trieble, The 8086 and 80286 Microprocessors, Hardware, Software, and Interfacing. Prentice-Hall Inc. 1990 
  3. Richard C Detmer, Fundamentals of Assembly Language Programming, Using IBM PC and Compatibles. DC Heath and Company. 1990.