---
# System prepended metadata

title: Homework Chapter 3-4
tags: [微算機與組合語言]

---

---
tags : 微算機與組合語言
---
###### 411085056 資工二 江宥旻
Homework Chapter 3-4
===
Please use the EMU86 emulator to complete following problems
1.	Please execute following instructions and find the content of following registers, AX, BX, and following flags CF, AF, PF, SF, ZF, OF after each instruction executed.
    MOV AX, 0EA34H
    MOV BX, 03D25H
    ADD AX, BX
    SUB AX, 01220H
    
    ```asm=
    name "ex1.asm"

    org 100h

    mov ax, 0xEA34
    mov bx, 0x3D25
    add ax, bx
    sub ax, 0x1220

    ret
    ```
    ![](https://i.imgur.com/T9Cadro.jpg =300x)
    ![](https://i.imgur.com/FyYIxoX.png =300x)
    ![](https://i.imgur.com/JziQb2h.png =300x)
    ![](https://i.imgur.com/fVSWQdT.png =300x)
    ![](https://i.imgur.com/OKSpxjY.png =300x)

2.	Please use the 8086’s assembly language to complete following statement of C language, and store the result into DX register. You can use any register to store the variable “a”. (Note: an integer is a 16-bits wide.)

    int a = (100-20) + (30-10)
    ```asm=
    name "ex2.asm"
    
    org 100h

    mov ax, 100
    sub ax, 20
    mov bx, 30
    sub bx, 10
    add ax, bx
    mov dx, ax

    ret            
    ```
    ![](https://i.imgur.com/IpWFA4A.jpg =300x)
    ![](https://i.imgur.com/yfP9IW3.jpg =300x)
    ![](https://i.imgur.com/bbhn950.png =300x)
    ![](https://i.imgur.com/lB7uu04.jpg =300x)
    ![](https://i.imgur.com/T5xhm06.jpg =300x)
    ![](https://i.imgur.com/PDDFRZ2.jpg =300x)
    ![](https://i.imgur.com/Rceme8Y.jpg =300x)
    
3.	Please use the 8086’s assembly language to complete following statement of C language, and store the result into DX:AX 

    int a = (107-53) x (100-25) x 12
    ```asm=
    name "ex3.asm"
    
    org 100h

    mov ax, 107
    sub ax, 53
    mov bx, 100
    sub bx, 25
    mul bx
    mov bx, 12
    mul bx

    ret
    ```
    ![](https://i.imgur.com/sATjjvg.png =300x)
    ![](https://i.imgur.com/rprdlnF.png =300x)
    ![](https://i.imgur.com/odxqwbX.jpg =300x)
    ![](https://i.imgur.com/LEP5vUS.png =300x)
    ![](https://i.imgur.com/XAnN7cj.jpg =300x)
    ![](https://i.imgur.com/IM5cOGL.jpg =300x)
    ![](https://i.imgur.com/ywq3fzw.jpg =300x)
    ![](https://i.imgur.com/C1SpUMr.jpg =300x)




4.	Please use the XLAT instruction of 8086’s assembly language to complete ASCII code translation. For example, the AX = 1, you should obtain the ASCII code of AX through the lookup table instruction (XLAT) to obtain the value 31(16), and store the result into DX. (Note: You should build a table into data segment (below the “.data” segment), so that you can look up the table using XLAT). 

    ```asm=
    name "ex4.asm"
    
    org 100h

    .data
    ascii db 30h, 31h, 32h, 33h, 34h, 35h, 36h, 37h, 38h, 39h 

    .code   

    lea bx, ascii
    mov al, 5
    xlat 
    mov dl, al
    
    ret
    ```
    ![](https://i.imgur.com/S7MI9OG.png =300x)
    ![](https://i.imgur.com/7S2zaPf.png =300x)
    ![](https://i.imgur.com/jhMCGUT.png =300x)
    ![](https://i.imgur.com/iuC1jaE.png =300x)
    ![](https://i.imgur.com/QXaMLFJ.png =300x)
    ![](https://i.imgur.com/XSBV1Nb.png =300x)

    > 去ascii[5]找值，找到35

    
5.	If you have two variables, a and b, which are 16-bits integers, please define these two variables in the .data segment and complete following statements in 8086 assembly language.

    int a = 10;
    int b;
    b = a + 10 - 5;
    a = b - 6;
    ```asm=
    name "ex5.asm"
    
    org 100h

    .data     

    a dw 10
    b dw ?

    .code

    mov ax, @data 
    mov ds, ax
    mov si, offset a
    mov ax, [si]
    mov bx, [si]  
    add bx, 10
    sub bx, 5
    mov si, offset b
    mov [si], bx
    sub bx, 6
    mov ax, bx
    mov si, offset a
    mov [si], ax

    ret
    ```
    ![](https://i.imgur.com/cAMOVSS.png =300x)
    > a在7102的位址，b在7104的位址
   
    ![](https://i.imgur.com/PEH4C6j.jpg =300x)
    ![](https://i.imgur.com/3ixSu7K.png =300x)
    ![](https://i.imgur.com/lILjDLw.jpg =300x)
    ![](https://i.imgur.com/LHfG41C.png =300x)
    ![](https://i.imgur.com/JYI3nJk.png =300x)
    ![](https://i.imgur.com/aoNotad.png =300x)
    ![](https://i.imgur.com/HmSGAbw.png =300x)
    ![](https://i.imgur.com/oEXnUDI.jpg =300x)
    ![](https://i.imgur.com/71pw3Vc.png =300x)
    ![](https://i.imgur.com/nhsEtwp.jpg =300x)
    > b的值為15

    ![](https://i.imgur.com/6vteDk0.jpg =300x)
    ![](https://i.imgur.com/acruc3p.png =300x)
    ![](https://i.imgur.com/oCty3O7.jpg =300x)
    ![](https://i.imgur.com/NpfMVhX.jpg =300x)
    > a的值為9
