Quantcast
Channel: Active questions tagged ubuntu - Stack Overflow
Viewing all articles
Browse latest Browse all 7072

How to properly print user input in the correct position in Assembly 32-bit

$
0
0

I am currently developing a simple "About me" section in the terminal. I am using NASM Assembly and running Ubuntu in Oracle VM. I am currently having trouble with printing the user input together with the label.The desired output should be label:userinput but what happens is only the AsciiArt and the label follow the correct cursor position but the user input is either scattered or not next to the label.Here's my assembly code so far:

section .data    clearScreen db 27, '[2J', 0          ; ANSI code to clear screen    asciiArt1 db 27, '[5;4H', "   _   _                 _                    ", 10, \              27, '[6;4H', "  /_\ | |__   ___  _   _| |_   _ __ ___   ___ ", 10, \              27, '[7;4H', " //_\\| '_ \ / _ \| | | | __| | '_ ` _ \ / _ \", 10, \              27, '[8;4H', "/  _  \ |_) | (_) | |_| | |_  | | | | | |  __/", 10, \              27, '[9;4H', "\_/ \_/_.__/ \___/ \__,_|\__| |_| |_| |_|\___|", 10, 0    cursorNameLabel db 27, '[8;65H'      ; Adjusted position for the name label    nameLabel db 'Name: ', 0    cursorEmailLabel db 27, '[12;4H'    ; Adjusted position for the email label    emailLabel db 'Email: ', 0    cursorBottom db 27, '[40;1H'section .bss    name resb 20     ; Reserve 20 bytes for the name    email resb 25    ; Reserve 25 bytes for the emailsection .text    global _start_start:    call clearTheScreen    call userInputs    call displayAsciiArt    call displayInfo    call exitProgramclearTheScreen:    mov eax, 4    mov ebx, 1    mov ecx, clearScreen    mov edx, 4    int 0x80    retuserInputs:    ; Input for name    mov eax, 4    mov ebx, 1    mov ecx, nameLabel    mov edx, 6          ; Length for the name label    int 0x80    mov eax, 3    mov ebx, 0    mov ecx, name    mov edx, 20          ; Max length for the name    int 0x80    ; Input for email    mov eax, 4    mov ebx, 1    mov ecx, emailLabel    mov edx, 8              int 0x80    mov eax, 3    mov ebx, 0    mov ecx, email    mov edx, 25          ; Max length for the email    int 0x80    retdisplayAsciiArt:    mov eax, 4    mov ebx, 1    mov ecx, asciiArt1    mov edx, 300         ; Total length of ASCII art    int 0x80    retdisplayInput:    ; Input parameters:     ; ecx = label address, edx = buffer address, ebx = cursor position    mov eax, 4          ; sys_write    mov ebx, 1          ; file descriptor (stdout)    ; Move cursor    mov ecx, [esp + 4]   ; Load cursor position from stack    mov edx, 32          ; Length for cursor    int 0x80            ; Write cursor position    ; Print label    mov ecx, [esp + 8]   ; Load the label address    mov edx, 32          ; Length of the label    int 0x80            ; Write label    ; Print input    mov ecx, [esp + 12]  ; Load the input address    mov edx, 20         ; Display name input length (or change to 25 for email)    int 0x80            ; Write input    retdisplayInfo:    ; Display Name    push cursorNameLabel ; Push cursor position for name    push nameLabel       ; Push name label    push name            ; Push name address    call displayInput    ; Call displayInput    add esp, 12         ; Clean up stack    ; Display Email    push cursorEmailLabel; Push cursor position for email    push emailLabel      ; Push email label    push email           ; Push email address    call displayInput    ; Call displayInput    add esp, 12         ; Clean up stack    retexitProgram:    ; Move cursor to the bottom before exiting    mov eax, 4    mov ebx, 1    mov ecx, cursorBottom    mov edx, 7    int 0x80    mov eax, 1    int 0x80

The output looks like this:Terminal

My code before is longer and decided to make it short so it's readable.I have more things to print out and I am testing out with 2 user inputs first.I just need the asciiart, label and userinput to print accordingly.


Viewing all articles
Browse latest Browse all 7072

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>