Home IA-32 beginner asm sys_write confusion
Reply: 0

IA-32 beginner asm sys_write confusion

1girl2pups
1#
1girl2pups Published in 2018-02-14 00:06:52Z

I'm using NASM, IA-32 (I think). The homework is to take ASCII from a .txt file and print it to the console in hexadecimal using linux shell input redirection. I think I've got the ascii to hex part figured out, but I'm having a hard time making it print the console correctly. I'm sure I'm just missing something small and silly. The file I'm reading just to test is something simple like this: ABC 123 The output should be: 41 42 43 0A 31 20 32 20 33 20

The problem is happening in

_hexOut:

I've tried changing more stuff around than I can fit in this post, and I can't figure out where I'm going wrong. The only output I'm getting is: 41 42 43

section .text   
    global _start
_start:
    mov edx, inBuffSize         ; sys_read
    mov ecx, inBuffer           ; -
    mov ebx, 0x00               ; -
    mov eax, 0x03               ; - 
    int 0x80                    ; end sys_read

    mov [inputLen], eax
    cmp eax, 0      
    jle _exit       

_inLeft:
    mov ecx, [inCount]          ; move 
    cmp ecx, [inputLen]                       
    je _hexOut                        
    movzx eax, byte [inBuffer + ecx]             
    mov [temp], al                   
    shr al, 4                        
    mov bl, 9                     
    cmp al, bl                         
    jle _leftIsNumber             
    mov bl, 10                        
    cmp al, bl                          
    jge _leftIsLetter           

_leftIsNumber:
    mov ecx, [outCount]                 
    add al, 48                         
    mov [outBuffer + ecx], al             
    mov ecx, [outCount]               
    inc ecx                           
    mov [outCount], ecx              
    jmp _inRight               

_leftIsLetter:
    mov ecx, [outCount]                 
    add al, 55                         
    mov [outBuffer + ecx], al           
    mov ecx, [outCount]                 
    inc ecx                            
    mov [outCount], ecx                
    jmp _inRight              

_inRight:
    mov ecx, [inCount]                  
    inc ecx                            
    mov [inCount], ecx                  
    movzx eax, byte [temp]                     
    and al, 0x0F                       
    mov bl, 9                          
    cmp al, bl                         
    jle _rightIsNumber              
    mov bl, 10                         
    cmp al, bl                     
    jge _rightIsLetter            

_rightIsNumber:
    mov ecx, [outCount]                 
    add al, 48                   
    mov [outBuffer + ecx], al       
    mov ecx, [outCount]            
    inc ecx                            
    mov [outBuffer + ecx], byte 32 
    inc ecx                       
    mov [outCount], ecx             
    jmp _inLeft                

_rightIsLetter:
    mov ecx, [outCount]                 
    add al, 55             
    mov [outBuffer + ecx], al            
    mov ecx, [outCount]                 
    inc ecx                          
    mov [outBuffer + ecx], byte 32        
    inc ecx                         
    mov [outCount], ecx                 
    jmp _inLeft              

_hexOut:;------------------ PROBLEMS HERE ----------------------
   ; mov ecx, [inputLen]           
   ; mov [outCount + ecx], byte 0x0A   
   ; inc ecx                         
   ; mov [inputLen], ecx             

    mov edx, [inputLen] 
    mov ecx, outBuffer  
    mov ebx, 0x01       
    mov eax, 0x04       
    int 0x80            
;------------------------------------------------------
_exit:
    mov ebx, 0
    mov eax, 1    
    int 0x80         


section .data   


section .bss 
    inBuffer resb inBuffSize
    outBuffer resb outBuffSize
    inBuffSize equ 200
    outBuffSize equ 600
    inCount resd 1
    outCount resd 1
    temp resb 1
    inputLen resd 1   

The second part of the problem is that I need to be able to change how many hex bytes are shown per line in the console, but I can't start to tackle that until I get the first problem solved. Any nudge in the right direction would be appreciated!

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.330983 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO