flat assembler
Message board for the users of flat assembler.

Index > Linux > Array

Author
Thread Post new topic Reply to topic
Rock24



Joined: 13 Feb 2015
Posts: 5
Rock24
Hello.
I am new in Assembler and I have my first big problem Smile
I would like to display on the screen second element of the list ( table).

Code:
format ELF64 executable ;wersja pliku
entry _start
segment readable executable
_start:
        mov rax,1
        mov rdi,1
        mov rsi,table
        mov rdx,[dlugosc]
        syscall
        
        mov rax,60
        syscall

segment readable writeable
table db "1","2","3","4"
dlugosc dq $ - table
    


I could write only this code. It shows all elements of the list
Post 13 Feb 2015, 22:05
View user's profile Send private message Reply with quote
alkap



Joined: 18 Feb 2015
Posts: 44
Location: Dnipro, Ukraine
alkap
I could be wrong, but perhaps the code below might do the trick. I'm not familiar with the x86-64 syscall calling convention, nor do I have access to an x86-64 machine, so I haven't been able to test my suggestion:
Code:
...
mov rax,1 
mov rdi,1
mov rsi, byte [table+1]
mov rdx, 1
syscall
...
    

Can you please give this a try and let us know how you go.
Post 16 Mar 2015, 11:05
View user's profile Send private message Send e-mail Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1180
Location: Unknown
HaHaAnonymous
Quote:

I would like to display on the screen second element of the list ( table).

If it is a table, then you may want an aligned table of strings... Because strings can have varying lengths.

Code:
format ELF64 executable ;wersja pliku 
entry _start 
segment readable executable 
_start: 
        mov rcx,table
        mov rax,1 
        mov rdi,1 
        ; writes the 2nd item
        lea rsi,[rcx+32+8]
        mov rdx,[rcx+32]
        syscall 
         
        mov rax,60 
        syscall 

segment readable writeable 

x = 32

align x
; alignment 32 is enough in this case because no item exceeds 32 bytes, in case one of your strings does, align to higher boundaries
table:
       dq $0000000000000002
       db ":D"

       align x
       dq $0000000000000004
       db "woof"

       align x
       dq $000000000000000A
       db "woof woof!"

       align x
       dq $0000000000000003
       db "o_O"
    


or alternatively this method:
Code:
format ELF64 executable ;wersja pliku 
entry _start 
segment readable executable 
_start: 
        mov rcx,table
        mov rax,1 
        mov rdi,1 
        ; writes the 2nd item
        mov rsi,[rcx+8*1]
        mov rdx,[rsi-8]
        syscall 
         
        mov rax,60 
        syscall 

segment readable writeable 

x = 8

align x
table:
       dq data0+x
       dq data1+x
       dq data2+x
       dq data3+x

align x
data0: dq $02
       db ":D"

align x
data1: dq $04
       db "woof"

align x
data2: dq $0A
       db "woof woof!"

align x
data3: dq $03
       db "o_O"
    

Not sure.
Post 16 Mar 2015, 16:19
View user's profile Send private message Reply with quote
Endre



Joined: 29 Dec 2003
Posts: 212
Location: Budapest, Hungary
Endre
I guess the OP wants something like this
Code:
format ELF64 executable ;wersja pliku
entry _start
segment readable executable
_start:
        mov rax,1
        mov rdi,1
        mov rsi,table+1
        mov rdx,1
        syscall
        
        mov rax,60
        syscall

segment readable writeable
table db "1","2","3","4"
dlugosc dq $ - table     
Post 22 Mar 2015, 11:55
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.