Microprocessors / DEBUG Lab Calculation and Comparisons

profilebeoto01
lab_04.doc

The Intel Family of Microprocessors

James L. Antonakos

Lab #4: Calculations and Comparisons

Reference: Chapter 4

Introduction

The purpose of this experiment is to see how typical mathematical calculations, as well as numeric and logical comparisons, are performed.

Procedure

1. The sun is 93,000,000 miles from the Earth. The speed of light is 186,000 miles/second. How long does it take a ray of light to reach the Earth? The correct answer is 8 minutes, 20 seconds. Enter and save the file SUN.SCR:

image1.png

2. Open a DOS window, and enter the following DEBUG command:

DEBUG < SUN.SCR

What is the final value in the AX register? Does it represent some combination of 8 and 20? Hint: Remember that DEBUG only works with hexadecimal numbers.

3. Explain how the calculations were performed in SUN.SCR. For example, were the numbers 93,000,000 and 186,000 represented anywhere? If not, why not?

4. Enter and save the file AVG.SCR and process it using DEBUG. What is the final value in AL? Explain why the value is correct.

image2.png

5. Enter and save the file CMPUNSGN.SCR. Then open a DOS window and enter the following command:

DEBUG < CMPUNSGN.SCR

Discuss the relationship between the instructions and the results indicated by the flags. Hint: See Example 4.7.

image3.png

6. Repeat step 5 using the file CMPSIGN.SCR:

image4.png

7. Enter and save the source file COMPARES.ASM. Assemble, link, and run. Examine the results.

;Program COMPARES.ASM: Compare two words of data different ways.
;
        .MODEL SMALL
        .DATA
NUM1    DW    25000
NUM2    DW    26000
AXMSG   DB    'AX equals$'
BXMSG   DB    'BX equals$'
MSG     DB    ' '
TENTHOS DB    ?
THOUS   DB    ?
HUNS    DB    ?
TENS    DB    ?
ONES    DB    ?
        DB    0DH,0AH,'$'
IMSG    DB    'Instruction: CMP AX,BX',13,10,'$'
JCTMSG  DB    'JC is True',13,10,'$'
JCFMSG  DB    'JC is False',13,10,'$'
JZTMSG  DB    'JZ is True',13,10,'$'
JZFMSG  DB    'JZ is False',13,10,'$'
JATMSG  DB    'JA is True',13,10,'$'
JAFMSG  DB    'JA is False',13,10,'$'
JLTMSG  DB    'JL is True',13,10,'$'
JLFMSG  DB    'JL is False',13,10,'$'
        .CODE
        .STARTUP
        LEA   DX,AXMSG          ;display AX value
        MOV   AH,9
        INT   21H
        MOV   AX,NUM1
        CALL  BTOD
        LEA   DX,MSG  
        MOV   AH,9
        INT   21H
        LEA   DX,BXMSG          ;display BX value
        MOV   AH,9
        INT   21H
        MOV   AX,NUM2           
        CALL  BTOD
        LEA   DX,MSG  
        MOV   AH,9
        INT   21H
        LEA   DX,IMSG           ;show 'CMP AX,BX'
        MOV   AH,9
        INT   21H
        MOV   AX,NUM1           ;start the comparisons
        MOV   BX,NUM2
        CALL  DOJC
        MOV   AX,NUM1
        MOV   BX,NUM2
        CALL  DOJZ
        MOV   AX,NUM1
        MOV   BX,NUM2
        CALL  DOJA
        MOV   AX,NUM1
        MOV   BX,NUM2
        CALL  DOJL
        .EXIT
DOJC    PROC  FAR
        CMP   AX,BX
        JC    JCOK
        LEA   DX,JCFMSG
        MOV   AH,9
        INT   21H
        RET
JCOK:   LEA   DX,JCTMSG
        MOV   AH,9
        INT   21H
        RET
DOJC    ENDP
DOJZ    PROC  FAR
        CMP   AX,BX
        JZ    JZOK
        LEA   DX,JZFMSG
        MOV   AH,9
        INT   21H
        RET
JZOK:   LEA   DX,JZTMSG
        MOV   AH,9
        INT   21H
        RET
DOJZ    ENDP
DOJA    PROC  FAR
        CMP   AX,BX
        JA    JAOK
        LEA   DX,JAFMSG
        MOV   AH,9
        INT   21H
        RET
JAOK:   LEA   DX,JATMSG
        MOV   AH,9
        INT   21H
        RET
DOJA    ENDP
DOJL    PROC  FAR
        CMP   AX,BX
        JL    JLOK
        LEA   DX,JLFMSG
        MOV   AH,9
        INT   21H
        RET
JLOK:   LEA   DX,JLTMSG
        MOV   AH,9
        INT   21H
        RET
DOJL    ENDP
BTOD    PROC  FAR
        SUB   DX,DX
        MOV   BX,10000
        DIV   BX                ;get 10,000s digit
        ADD   AL,30H
        MOV   TENTHOS,AL
        XCHG  AX,DX
        SUB   DX,DX
        MOV   BX,1000           ;get 1,000s digit
        DIV   BX
        ADD   AL,30H
        MOV   THOUS,AL
        XCHG  DX,AX
        MOV   BL,100
        DIV   BL          ;get hundreds digit
        ADD   AL,30H      ;convert into ASCII digit
        MOV   HUNS,AL     ;and save
        XCHG  AL,AH       ;get remainder
        SUB   AH,AH       ;prepare for division by 10
        MOV   BL,10
        DIV   BL          ;get tens digit
        ADD   AL,30H      ;convert into ASCII digit
        MOV   TENS,AL     ;and save
        ADD   AH,30H      ;convert ones digit into ASCII
        MOV   ONES,AH     ;and save
        RET
BTOD    ENDP
        END

8. Choose four additional types of conditional jump instructions and add the appropriate procedures to test the new jump instructions. Your final program will show the results of eight comparisons. Include the list file with your writeup.

9. Write a one-page summary of what you learned during the laboratory.

PAGE

5