Advertisement
kevinmthomas

input.asm 08/25/2016

Aug 25th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;executable name:   input.asm
  2. ;version:           1.0
  3. ;created date:      08/24/16
  4. ;last update:       08/25/16
  5. ;author:            Kevin M. Thomas
  6. ;description:       app that accepts only proper int input of 4 bytes
  7. ;run:               ./input
  8. ;compile:           nasm -f elf32 input.asm
  9. ;link:              ld -m elf_i386 -o input input.o
  10.  
  11. %include 'functions.asm'            ;include external library
  12.  
  13. SECTION .data                       ;initialized data section
  14.     prompt_input db 'Enter 4 Numbers ONLY:  '
  15.     prompt_inputLEN equ $ - prompt_input
  16.     buffer times 4 db 0            
  17.     bufferLEN equ $ - buffer
  18.     display_buffer db 'Buffer:  '
  19.     display_bufferLEN equ $ - display_buffer        
  20.  
  21. SECTION .bss                        ;unitialized data section
  22.     kb_input resb 1        
  23.  
  24. SECTION .text
  25.     global _start
  26.  
  27. _start:
  28.     nop                             ;for debugging purposes
  29.  
  30.     call clear_screen               ;cal clear_screen function
  31.  
  32. prompt_input_message:
  33.     mov ecx, prompt_input           ;mov prompt_input to ECX
  34.     mov edx, prompt_inputLEN        ;mov LEN to EDX
  35.     call write_message              ;call write_message function
  36.    
  37.     call canonical_off              ;call canonical_off function
  38.    
  39.     mov ebx, buffer                 ;base address pointer to buffer
  40.     mov ecx, 4                      ;counter total bytes to get of kb_input
  41.  
  42. get_kb_input:
  43.     call read                       ;call read function
  44.    
  45.     mov al, byte[kb_input]          ;move single keypress into al
  46.  
  47.     cmp al, 30h                     ;cmp ASCII 0 to al
  48.     jb invalid_kb_input             ;jmp if below
  49.  
  50.     cmp al, 39h                     ;cmp ASCII 9 to al
  51.     ja invalid_kb_input             ;jmp if above
  52.  
  53.     mov byte[ebx], al               ;store valid byte to EBX pointer
  54.  
  55.     add ebx, 1                      ;advance pointer 1b to next kb_input
  56.    
  57.     call write                      ;call write function
  58.  
  59.     jmp next_byte                   ;jmp next_byte
  60.  
  61. invalid_kb_input:
  62.     add ecx, 1                      ;compensation what loop takes away
  63.  
  64. next_byte:
  65.     mov byte[kb_input], 0           ;mov 0 into byte of kb_input
  66.     loop get_kb_input               ;loop get_kb_input
  67.  
  68.     call canonical_on               ;call canonical_on function
  69.  
  70.     call new_line                   ;call new_line function
  71.  
  72. display_buffer_message:
  73.     mov ecx, display_buffer         ;mov display_buffer to ECX
  74.     mov edx, display_bufferLEN      ;mov LEN to EDX
  75.     call write_message              ;call write_message function
  76.  
  77. display_buffer_data:
  78.     mov ecx, buffer                 ;mov buffer to ECX
  79.     mov edx, bufferLEN              ;mov LEN to EDX
  80.     call write_message              ;call write_message function
  81.  
  82.     call new_line                   ;call new_line function
  83.  
  84.     call exit                       ;call exit function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement