Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;executable name: input.asm
- ;version: 1.0
- ;created date: 08/24/16
- ;last update: 08/25/16
- ;author: Kevin M. Thomas
- ;description: app that accepts only proper int input of 4 bytes
- ;run: ./input
- ;compile: nasm -f elf32 input.asm
- ;link: ld -m elf_i386 -o input input.o
- %include 'functions.asm' ;include external library
- SECTION .data ;initialized data section
- prompt_input db 'Enter 4 Numbers ONLY: '
- prompt_inputLEN equ $ - prompt_input
- buffer times 4 db 0
- bufferLEN equ $ - buffer
- display_buffer db 'Buffer: '
- display_bufferLEN equ $ - display_buffer
- SECTION .bss ;unitialized data section
- kb_input resb 1
- SECTION .text
- global _start
- _start:
- nop ;for debugging purposes
- call clear_screen ;cal clear_screen function
- prompt_input_message:
- mov ecx, prompt_input ;mov prompt_input to ECX
- mov edx, prompt_inputLEN ;mov LEN to EDX
- call write_message ;call write_message function
- call canonical_off ;call canonical_off function
- mov ebx, buffer ;base address pointer to buffer
- mov ecx, 4 ;counter total bytes to get of kb_input
- get_kb_input:
- call read ;call read function
- mov al, byte[kb_input] ;move single keypress into al
- cmp al, 30h ;cmp ASCII 0 to al
- jb invalid_kb_input ;jmp if below
- cmp al, 39h ;cmp ASCII 9 to al
- ja invalid_kb_input ;jmp if above
- mov byte[ebx], al ;store valid byte to EBX pointer
- add ebx, 1 ;advance pointer 1b to next kb_input
- call write ;call write function
- jmp next_byte ;jmp next_byte
- invalid_kb_input:
- add ecx, 1 ;compensation what loop takes away
- next_byte:
- mov byte[kb_input], 0 ;mov 0 into byte of kb_input
- loop get_kb_input ;loop get_kb_input
- call canonical_on ;call canonical_on function
- call new_line ;call new_line function
- display_buffer_message:
- mov ecx, display_buffer ;mov display_buffer to ECX
- mov edx, display_bufferLEN ;mov LEN to EDX
- call write_message ;call write_message function
- display_buffer_data:
- mov ecx, buffer ;mov buffer to ECX
- mov edx, bufferLEN ;mov LEN to EDX
- call write_message ;call write_message function
- call new_line ;call new_line function
- call exit ;call exit function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement