flat assembler
Message board for the users of flat assembler.

Index > Linux > Variable Strings

Author
Thread Post new topic Reply to topic
asmblr_88



Joined: 12 Jan 2023
Posts: 12
asmblr_88 06 Feb 2023, 20:13
Hello all,

I am trying to write a program that prints out a concatenated string.

Without the newline it concatenates as expected, but my main issue is the fact that it prints out both variables instead of just one of them.

I wrote the program to print out only one of the variables but for some reason it seems to take in both variables (as arguments?) and print them out onto the screen.

Also it seems to echo the second variable after printing out both variables on one line.

This is the code: multistring.asm

│ File: multistring.asm
───────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1 │ format ELF64 executable 3
2 │
3 │ SYS_EXIT equ 60
4 │ EXIT_SUCCESS equ 0
5 │ WRITE_OUTPUT equ 1
6 │ STANDARD_OUTPUT equ 1
7 │ NL equ 0xA
8 │
9 │ segment readable executable
10 │
11 │ entry $
12 │
13 │
14 │ ;;;;;;;;;;;;;;;;;;;;;;;;;;
15 │ ;; OUTPUT FIRST MESSAGE ;;
16 │ ;;;;;;;;;;;;;;;;;;;;;;;;;;
17 │
18 │ mov rdx, msg1_len
19 │ lea rsi, [msg1]
20 │ mov rdi, STANDARD_OUTPUT
21 │ mov rax, WRITE_OUTPUT
22 │ syscall
23 │
24 │ ;;;;;;;;;;;;;;;;;;;;;;;;;;;
25 │ ;; OUTPUT SECOND MESSAGE ;;
26 │ ;;;;;;;;;;;;;;;;;;;;;;;;;;;
27 │
28 │ ; mov rdx, msg2_len
29 │ ; lea rsi, [msg2]
30 │ ; mov rdi, STANDARD_OUTPUT
31 │ ; mov rax, WRITE_OUTPUT
32 │ ; syscall
33 │ ;;;;;;;;;;;;;;;;;;;;;;
34 │ ;; EXIT THE PROGRAM ;;
35 │ ;;;;;;;;;;;;;;;;;;;;;;
36 │
37 │
38 │ mov rax, SYS_EXIT
39 │ mov rdi, EXIT_SUCCESS
40 │ syscall
41 │
42 │
43 │ ;;;;;;;;;;;;;;;;;;;;;;;
44 │ ;; DECLARE VARIABLES ;;
45 │ ;;;;;;;;;;;;;;;;;;;;;;;
46 │
47 │ msg1 db NL,NL,"Hello, "
48 │ msg2 db "there!",NL,NL
49 │
50 │ msg1_len = $-msg1
51 │ msg2_len = $-msg2


END OF CODE

I appreciate any and all help. I hope all of you have a great day!

_________________
asmblr_88
Post 06 Feb 2023, 20:13
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 06 Feb 2023, 20:55
The length of msg_1 is not correct. Something like this might help.
Code:
47 │ msg1 db NL,NL,"Hello, "
50 │ msg1_len = $-msg1
4948 │ msg2 db "there!",NL,NL
51 │ msg2_len = $-msg2    
Post 06 Feb 2023, 20:55
View user's profile Send private message Visit poster's website Reply with quote
asmblr_88



Joined: 12 Jan 2023
Posts: 12
asmblr_88 07 Feb 2023, 04:32
I tried it and it worked. Thanks revolution!

I am wondering about how string interpolation or how placeholders work (like %d in C for example), because I am trying to understand how printf works.

Is it all concatenation of strings? Does the assembler have to convert the numbers into strings?

Thanks again! I hope you have a great day!
Post 07 Feb 2023, 04:32
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 07 Feb 2023, 04:36
The strings are just laid in memory joined together. If you have a hex dump program you can examine the file to see the result.
Post 07 Feb 2023, 04:36
View user's profile Send private message Visit poster's website Reply with quote
asmblr_88



Joined: 12 Jan 2023
Posts: 12
asmblr_88 07 Feb 2023, 10:15
That makes sense.

Thanks again revolution!

_________________
asmblr_88
Post 07 Feb 2023, 10:15
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.