---
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
```





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
```







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
```








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
```






> 去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
```

> a在7102的位址,b在7104的位址










> b的值為15




> a的值為9