1.
section .data
str1 db "Hello", 0
str2 db "World", 0
fmt db "Common byte: %c", 10, 0
section .text
global main
extern printf
main:
mov esi, str1
mov edi, str2
find_common:
mov al, [esi]
mov bl, [edi]
and al, bl
jz no_common
push eax
push fmt
call printf
add esp, 8
jmp end
no_common:
mov eax, 0
end:
ret
2.
section .data
string db "Hello World", 0
replacement db '*'
fmt db "Result: %s", 10, 0
section .text
global main
extern printf, strlen
main:
push string
call strlen
add esp, 4
mov ecx, eax
shr ecx, 1 ; divide length by 2
mov esi, string
add esi, ecx ; move to middle of string
replace_loop:
mov byte [esi], '*'
inc esi
loop replace_loop
push string
push fmt
call printf
add esp, 8
ret
3.
section .data
string db "ABRACADABRA", 0
replacement db '*'
fmt db "Result: %s", 10, 0
section .text
global main
extern printf
main:
mov esi, string
replace_loop:
mov al, [esi]
test al, al
jz end_loop
cmp al, 'A'
jne next_char
mov byte [esi], '*'
next_char:
inc esi
jmp replace_loop
end_loop:
push string
push fmt
call printf
add esp, 8
ret
4.
section .data
string db "Hello World", 0
replacement db '*'
fmt db "Result: %s", 10, 0
section .text
global main
extern printf, strlen
main:
push string
call strlen
add esp, 4
mov ecx, eax
shr ecx, 1 ; divide length by 2
mov esi, string
replace_loop:
mov byte [esi], '*'
inc esi
loop replace_loop
push string
push fmt
call printf
add esp, 8
ret
5.
section .data
original db "Hello World", 0
modified db "Hello World", 0
replacement db '*'
fmt1 db "Original: %s", 10, 0
fmt2 db "Modified: %s", 10, 0
section .text
global main
extern printf, strlen
main:
push original
push fmt1
call printf
add esp, 8
push original
call strlen
add esp, 4
mov ecx, eax
mov esi, modified
replace_loop:
mov byte [esi], '*'
inc esi
loop replace_loop
push modified
push fmt2
call printf
add esp, 8
ret
https://drive.google.com/file/d/1k6hvHSKQUZsQ2UGpRnty-cqEjL_PXVtU/view?usp=sharing