Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- section .data
- msg_zero_div db "ERROR: Zero division!", 10
- len_zero_div equ $ - msg_zero_div
- msg_negative db "Negative numerator", 10
- len_negative equ $ - msg_negative
- msg_zero db "0", 10
- len_zero equ $ - msg_zero
- msg_cat db "quo="
- len_cat equ $ - msg_cat
- msg_rest db 10, "rem="
- len_rest equ $ - msg_rest
- newline db 10
- section .bss
- a resb 2
- b resb 2
- c resb 2
- quo resb 2
- rem resb 2
- section .text
- global _start
- _start:
- ; read A
- mov eax, 3
- mov ebx, 0
- mov ecx, a
- mov edx, 2
- int 0x80
- ; read B
- mov eax, 3
- mov ebx, 0
- mov ecx, b
- mov edx, 2
- int 0x80
- ; read C
- mov eax, 3
- mov ebx, 0
- mov ecx, c
- mov edx, 2
- int 0x80
- ; compute
- movzx eax, byte [a]
- sub eax, '0'
- mov ebx, 2
- mul ebx ; 2A
- mov ebx, eax
- movzx eax, byte [b]
- sub eax, '0'
- mov ecx, 3
- mul ecx ; 3B
- sub ebx, eax
- ; if quo is 0
- cmp ebx, 0
- je zero_result
- ; if quo < 0
- cmp ebx, 0
- jl negative_result
- movzx ecx, byte [c]
- sub ecx, '0'
- mov eax, 5
- mul ecx ; 5C
- ; if zero div
- cmp eax, 0
- je zero_division
- mov ecx, eax
- mov eax, ebx
- cdq
- div ecx
- ; print quo
- add eax, '0'
- mov [quo], al
- mov eax, 4
- mov ebx, 1
- mov ecx, msg_cat
- mov edx, len_cat
- int 0x80
- mov eax, 4
- mov ebx, 1
- mov ecx, quo
- mov edx, 1
- int 0x80
- ; print quo
- mov eax, edx
- add eax, '0'
- mov [rem], al
- mov eax, 4
- mov ebx, 1
- mov ecx, msg_rest
- mov edx, len_rest
- int 0x80
- mov eax, 4
- mov ebx, 1
- mov ecx, rem
- mov edx, 1
- int 0x80
- mov eax, 4
- mov ebx, 1
- mov ecx, newline
- mov edx, 1
- int 0x80
- jmp exit
- zero_division:
- mov eax, 4
- mov ebx, 1
- mov ecx, msg_zero_div
- mov edx, len_zero_div
- int 0x80
- jmp exit
- negative_result:
- mov eax, 4
- mov ebx, 1
- mov ecx, msg_negative
- mov edx, len_negative
- int 0x80
- jmp exit
- zero_result:
- mov eax, 4
- mov ebx, 1
- mov ecx, msg_zero
- mov edx, len_zero
- int 0x80
- jmp exit
- exit:
- mov eax, 1
- xor ebx, ebx
- int 0x80
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement