Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Generated by toASM
- KERN_INT equ 80h
- SYS_OUT equ 4
- SYS_IN equ 3
- SYS_EXIT equ 1
- STDOUT equ 1
- STDIN equ 0
- section .data
- section .bss
- _sbuf resb 255
- _ibuf resd 1
- _vsbuf resd 1
- _v0 resd 1 ;a
- _v1 resd 1 ;b
- section .text
- global _start
- _start:
- ;read(a)
- mov ecx, _sbuf
- mov edx, 255
- call _read
- call string_to_int
- mov eax, [_ibuf]
- mov [_v0], eax
- ;read(b)
- mov ecx, _sbuf
- mov edx, 255
- call _read
- call string_to_int
- mov eax, [_ibuf]
- mov [_v1], eax
- ;print(a)
- mov eax, [_v0]
- mov [_ibuf], eax
- call int_to_string
- mov ecx, _sbuf
- mov edx, 255
- call _print
- ;print(b)
- mov eax, [_v1]
- mov [_ibuf], eax
- call int_to_string
- mov ecx, _sbuf
- mov edx, 255
- call _print
- ._exit_point:
- mov eax, SYS_EXIT
- int KERN_INT
- ; Subroutines
- _read:
- push eax
- push ebx
- mov eax, SYS_IN
- mov ebx, STDIN
- int KERN_INT
- dec eax
- mov [_vsbuf], eax
- pop ebx
- pop eax
- ret
- string_to_int:
- push ebx
- push ecx
- push edx
- push esi
- push edi
- mov eax, [_vsbuf]
- xor edi, edi
- mov ebx, 0
- .loop:
- imul ebx, ebx, 10
- add bl, [_sbuf+edi]
- sub bl, '0'
- inc edi
- cmp edi, eax
- jl .loop
- mov [_ibuf], ebx
- pop edi
- pop esi
- pop edx
- pop ecx
- pop ebx
- ret
- _print:
- push eax
- push ebx
- mov eax, SYS_OUT
- mov ebx, STDOUT
- int KERN_INT
- pop ebx
- pop eax
- ret
- int_to_string:
- push eax
- push ebx
- push ecx
- push edx
- push esi
- push edi
- mov eax, [_ibuf]
- xor edi, edi
- mov ecx, 10
- .ciclo:
- xor edx, edx
- idiv ecx
- add edx, '0'
- mov [_sbuf+edi], dl
- inc edi
- cmp eax, 0
- jg .ciclo
- mov edx, edi
- shr edx, 1
- xor esi, esi
- .invert:
- mov al, [_sbuf+esi]
- mov bl, [_sbuf+edi]
- xchg al, bl
- mov [_sbuf+esi], al
- mov [_sbuf+edi], bl
- dec edi
- inc esi
- cmp edi, edx
- jg .invert
- pop edi
- pop esi
- pop edx
- pop ecx
- pop ebx
- pop eax
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement