You are on page 1of 4

1.

Tự viết 1 Chương trình sử dụng những instruction học trong chuong 7 với tối thiểu 30 dòng
bằng Assemply

section .data ; if the result is not greater than 10, exit


the program
num1 dd 5 ; first number
mov eax, 1 ; syscall for sys_exit
num2 dd 7 ; second number
xor ebx, ebx ; return 0 status
section .bss
int 0x80 ; call kernel
result resd 1 ; reserve space for the result
greater_than:
section .text
; if the result is greater than 10, print a
global _start message
_start: mov eax, 4 ; syscall for sys_write
; load the first number into the mov ebx, 1 ; file descriptor for stdout
accumulator
mov ecx, message
mov eax, [num1]
mov edx, length
; add the second number to the
accumulator int 0x80 ; call kernel

add eax, [num2] ; exit the program

; subtract 5 from the accumulator mov eax, 1 ; syscall for sys_exit

sub eax, 5 xor ebx, ebx ; return 0 status

; store the result in the result variable int 0x80 ; call kernel

mov [result], eax message db "The result is greater than 10!",


0xA ; message to print
; check if the result is greater than 10
length equ $ - message ; length of the
cmp eax, 10 message
jg greater_than

2. Liệt kê các Instruction ý nghĩa được sử dụng trong câu 1

mov eax, [num1]: Đưa giá trị của biến num1 vào ô đặt biến eax.

add eax, [num2]: Cộng giá trị của biến num2 vào ô đặt biến eax.

sub eax, 5: Trừ 5 khỏi giá trị hiện tại của ô đặt biến eax.

mov [result], eax: Đưa giá trị hiện tại của ô đặt biến eax vào biến result.
cmp eax, 10: So sánh giá trị hiện tại của ô đặt biến eax với số 10.

jg greater_than: Nếu giá trị hiện tại của ô đặt biến eax lớn hơn 10, nhảy đến nhãn greater_than.

mov eax, 1: Đưa giá trị 1 vào ô đặt biến eax.

xor ebx, ebx: Đặt giá trị của ô đặt biến ebx thành 0.

int 0x80: Gọi hệ thống để thực hiện các hành động yêu cầu (trong trường hợp này, đó là thoát
chương trình).

mov eax, 4: Đưa giá trị 4 vào ô đặt biến eax.

mov ebx, 1: Đưa giá trị 1 vào ô đặt biến ebx.

mov ecx, message: Đưa địa chỉ của biến message vào ô đặt biến ecx.

mov edx, length: Đưa giá trị của biến length vào ô đặt biến edx.

int 0x80: Gọi hệ thống để thực hiện các hành động yêu cầu (trong trường hợp này, đó là in ra màn
hình).

mov eax, 1: Đưa giá trị 1 vào ô đặt biến eax.

xor ebx, ebx: Đặt giá trị của ô đặt biến ebx thành 0.

int 0x80: Gọi hệ thống để thực hiện các hành động yêu cầu (trong trường hợp này, đó là thoát
chương trình).

3. Tạo 20 câu Q& A cho các Instruction chuong 7

Instruction jmp được sử dụng để thực hiện việc jump unconditional trong Assembly language. Là
instruction nào?

a) jmp

b) jz

c) jnz

d) je

e) jne

Để jump đến một label trong một section khác của chương trình, instruction nào được sử dụng?

a) jmp

b) jmp short

c) jmp near
d) jmp far

e) jmp nearptr

Để thực hiện một jump đến một label theo một điều kiện nhất định trong Assembly language,
instruction nào được sử dụng?

a) jmp

b) jmp if

c) jz

d) jnz

e) je

Để thực hiện một jump đến một label theo một điều kiện nhất định trong Assembly language
nếu flag zero clear, instruction nào được sử dụng?

a) jz

b) jnz

c) je

d) jne

e) jc

Để thực hiện một jump đến một label theo một điều kiện nhất định trong Assembly language
nếu flag carry set, instruction nào được sử dụng?

a) jc

b) jnc

c) jz

d) jnz

e) js

Instruction call được sử dụng để thực hiện việc gọi một hàm trong Assembly language. Là
instruction nào?

a) call

b) call near

c) call far

d) call nearptr
e) call proc

Instruction ret được sử dụng để trả lời một gọi hàm trong Assembly language. Là instruction
nào?

a) ret

b) retf

c) retn

d) ret far

e) ret near

Instruction push được sử dụng để đẩy một giá trị lên stack trong Assembly language. Là
instruction nào?

a) push

b) push short

c) push near

d) push far

e) push nearptr

Instruction pop được sử dụng để lấy một giá trị từ stack trong Assembly language. Là instruction
nào?

a) pop

b) pop short

c) pop near

d) pop far

e) pop nearptr

You might also like