0

I want to change the string to all caps, although I am having trouble getting the length of the input. What i have tried so far is moving the address of the message into a registrar then indexing through the string and also increment a counter variable. Then comparing the char in the address to a '.' (signifying the end of the message) and if its found not to be equal it will recall this block of statements. At least this is what I want my code to do. Not sure if this is even the right logic. I know there are alot of errors and its messy but I'm learning so please just focus on my main question. thank you! EDIT: the input i use is 'this is a TEST.'

    ;nasm 2.11.08
    SYS_Write equ 4
    SYS_Read  equ 3
    STDIN     equ 0
    STDOUT    equ 1

    section .bss
        message resb 15
        counter resb 2
    section .data

        msg1: db 'Enter input (with a period) that I will turn into all capitals!',0xa ;msg for input
        len1 equ $- msg1



    section .text
        global _start

    _start:
        mov eax, SYS_Write    ; The system call for write (sys_write)
        mov ebx, STDOUT       ; File descriptor 1 - standard output
        mov ecx, msg1         ; msg to print
        mov edx, len1         ; len of message
        int 0x80              ; Call the kernel

        mov eax, SYS_Read     ;system call to read input
        mov ebx, STDIN        ;file descriptor
        mov ecx, message      ;variable for input
        mov edx, 15           ;size of message
        int 0x80              ;kernel call

        mov [counter], byte '0'

    getLen:
        mov eax, message
        add eax, [counter]
        inc byte [counter]
        cmp eax, '.'
        jne getLen

        mov eax, SYS_Write    ; this is to print the counter to make sure it got the right len
        mov ebx, STDOUT       
        mov ecx, counter      
        mov edx, 2            
        int 0x80

        jmp end


    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;    
        mov eax, [message]
        ;add eax, counter
        cmp eax, 90
        jg toUpper

    toUpper:
        sub eax, 32
        mov [message], eax

        mov eax, SYS_Write    ; The system call for write (sys_write)
        mov ebx, STDOUT       ; File descriptor 1 - standard output
        mov ecx, message         ; Put the offset of hello in ecx
        mov edx, 10          ; helloLen is a constant, so we don't need to say
        int 0x80              ; Call the kernel
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;    


    end:    
        mov eax,1            ; The system call for exit (sys_exit)
        mov ebx,0            ; Exit with return code of 0 (no error)
        int 0x80             ;
walshline
  • 7
  • 5
  • `mov eax, [message]` is a 4-byte load, so it's looking at 4 chars at once. Also, `jg toUpper` falls through to the same place as the branch target, and the code after `jmp end` is unreachable. Also, `c -= 32` only works on lower-case alphabetic characters. [What is the idea behind ^= 32, that converts lowercase letters to upper and vice versa?](//stackoverflow.com/a/54585515) and [Convert a String In C++ To Upper Case](//stackoverflow.com/a/37151084) – Peter Cordes Feb 16 '20 at 20:14
  • Thank you! I realize that some code is rendered useless/falls through as that is for my testing purpose! – walshline Feb 16 '20 at 20:20
  • Why did you close it? it still doesnt work with the al registar and those questions do not answer mine. Also I was just going to check if the letter is lower or greater than 90 - ascii Z and then jump to make it capital if needed, do not need to go the other way @Peter Cordes – walshline Feb 16 '20 at 20:36
  • Because it's basically the same problem, and [X86 NASM Assembly converting lower to upper and upper to lowercase characters](//stackoverflow.com/q/22058164) has code you can simplify to do just the one direction you need. And more importantly, answers that explain what you need to do to one ASCII character separately: in this case `and` with `~0x20` to clear the lower-case bit (if it's alphabetic). – Peter Cordes Feb 16 '20 at 20:57

0 Answers0