NASM Forum > Example Code

How to read a string using call read_int or call read_char and split to array?

(1/1)

kingpoop:
Hello,
So i am new to assembler and am struggling trying to read a value such as 10001010 using either
call read_int
or
call read_char
and then taking that input from the keyboard and splitting into an array such as
[1][0][0][0][1][0][1][0]

Is this even possible?
thank you for any advice, and i appreciate any coding help.  Here is what i have so far.

%include "/usr/local/share/asm_io.inc"

segment .data
    message       db "Enter code?: ",0
   
    var1          dd 123
    bitmask       dd 1,1,1,0,0,0,1,1
    mask          dd 11100011
   
segment .bss
    cook resd 8

segment .text
   global  asm_main

asm_main:
   push   ebp
   mov    ebp, esp
   ;********** CODE STARTS HERE **********


        ;;;;;;;;;;;;;;;;
        ;INIT
        ;;;;;;;;;;;;;;;;
        mov eax, 0
        mov ebx, 0
        topinit:
        cmp ebx, 8
        jge endinit
        mov DWORD [cook + ebx * 4], eax
        inc ebx
        jmp topinit
        endinit:

        ;;;;;;;;;;;;;;;;
        ;cook
        ;;;;;;;;;;;;;;;;
        cld ;clear destination flag
       
        mov eax, message        ;display message
        call print_string
       
        ;call read_char
        call read_int

        mov DWORD [var1], eax

        call read_char  ;\n

        mov eax, DWORD [var1]
       
        dump_regs 1
        call print_int

        jmp endloop2
       
                               
        endloop2:     
        call print_nl

   ; *********** CODE ENDS HERE ***********
   mov      eax, 0
   mov      esp, ebp
   pop      ebp
   ret

Navigation

[0] Message Index

Go to full version