Lab - Assignment - 1 SP21-BCS-022
Lab - Assignment - 1 SP21-BCS-022
(SP21-BCS-022 6A)
Submitted To
Sir Taimur Shahzad
Question No 1
section .data
section .bss
section .text
global _start
_start:
mov eax, 4
mov ebx, 1
mov edx, 23
int 0x80
mov eax, 3
mov ebx, 0
int 0x80
mov eax, 4
mov ebx, 1
mov edx, 24
int 0x80
mov eax, 3
mov ebx, 0
int 0x80
check_strings:
je end_of_program
xor al, bl
count_bits:
shr al, 1
adc ah, 0
loop count_bits
add eax, cx
inc str1
inc str2
jmp check_strings
end_of_program:
Question No 2
section .data
section .bss
section .text
global _start
_start:
mov eax, 4
mov ebx, 1
mov edx, 25
int 0x80
mov eax, 3
mov ebx, 0
mov edx, 11
int 0x80
validate_isbn:
je end_of_program
dec ecx
inc isbn
jmp validate_isbn
end_of_program:
mov ecx, 11
cmp edx, 0
je valid_isbn
jmp invalid_isbn
valid_isbn:
mov eax, 4
mov ebx, 1
mov edx, 12
int 0x80
jmp end_of_program
invalid_isbn:
mov eax, 4
mov ebx, 1
mov edx, 14
int 0x80
mov eax, 1
int 0x80
Question No 3
section .data
section .bss
result resd 1
section .text
global _start
_start:
mov eax, 4
mov ebx, 1
mov edx, 29
int 0x80
mov eax, 3
mov ebx, 0
call evaluate_postfix
mov eax, 4
mov ebx, 1
mov edx, 8
int 0x80
mov eax, 1
mov ebx, 1
mov edx, 4
int 0x80
mov eax, 1
int 0x80
evaluate_postfix:
; Initialize registers
loop_postfix:
je end_evaluation
jl is_operator
inc ecx
inc ebx
jmp loop_postfix
is_operator:
; Pop two operands from the stack
pop eax
pop ebx
je add_operands
je sub_operands
je mul_operands
je div_operands
add_operands:
jmp push_result
sub_operands:
jmp push_result
mul_operands:
jmp push_result
div_operands:
cmp ebx, 0
je push_result
div ebx
jmp push_result
push_result:
push eax
inc ebx
jmp loop_postfix
end_evaluation:
pop eax
ret