8-masala. Quyida C++ tilida dastur qismi berilgan. Shu dastur qismiga mos assembler dastur kodini keltiring.
short int a=10;
int b=20,c;
c=a+b
JAVOB:
section .text
global add
add:
movsx eax, word [esp + 4] ; short int a
mov ebx, [esp + 8] ; int b
add eax, ebx ; a + b
ret
10-masala. Berilgan uchta butun son ichidan eng kattasini aniqlovchi dastur tuzilsin.
JAVOB :
section .data
a dd 10
b dd 20
c dd 15
max dd 0
section .text
global _start
_start:
; a ni max ga saqlash
mov eax, [a]
mov [max], eax
; b ni max bilan solishtirish
mov eax, [b]
cmp eax, [max]
jg update_max
; c ni max bilan solishtirish
mov eax, [c]
cmp eax, [max]
jg update_max
jmp done
update_max:
mov [max], eax
done:
; Natijani ekranga chiqarish
mov eax, 4
mov ebx, 1
mov ecx, max
mov edx, 4
int 0x80
; Dastur tugashi
mov eax, 1
xor ebx, ebx
int 0x80
Dostları ilə paylaş: |