flat assembler
Message board for the users of flat assembler.
Index
> Linux > String Interpolation |
Author |
|
asmblr_88 17 Jun 2023, 17:08
Hello, all.
I have been trying to write a program using fasm to take in user input, and respond with the user's name. EXAMPLE: The Computer: What is your name? The User: John The Computer: Hello, John! It was nice to meet you, I must go now, bye! It works, however I cannot get it to print a period or an exclamation mark at the end of the response to the user. It just ends up like this: Hello, John I have tried bumping up the byte count in rdx bye one or two but it only ends up adding a newline or linefeed after the name in the response. I cannot trail a period into the input stream of the response? I appreciate anyone who can help me with this conundrum. I will post the code in the thread. I hope everyone has a great day!
_________________ asmblr_88 |
|||||||||||
17 Jun 2023, 17:08 |
|
asmblr_88 18 Jun 2023, 07:54
I am not completely familiar with using hexdump or strace, so I will study up more on how to use it and hopefully I will understand this better.
Thank's a lot redsock! Much appreciated! I hope you have a great day. |
|||
18 Jun 2023, 07:54 |
|
Flier-Mate 18 Jun 2023, 11:42
I refer to hexdump by redsock:
Code: 00000000 57 68 61 74 20 69 73 20 79 6f 75 72 20 6e 61 6d |What is your nam| 00000010 65 3f 20 48 65 6c 6c 6f 2c 20 74 65 73 74 0a 00 |e? Hello, test..| 00000020 00 00 00 00 00 00 2e 0a 49 74 20 77 61 73 20 6e |........It was n| It is because a linefeed character is appended to the input buffer (name). So if user enters a name less than 12 chars, you will print 0xa (linefeed) as well carried from the input buffer. The hexdump above : "Hello, test", immediately followed by one linefeed (0xa), and seven null chars (0x), so 4 ("test") + 1 (linefeed) + 7 (null) made up 12 bytes. Now if you type "123456789012" as the input name, you will get the result you want, because 12 bytes could not contain 13th char which is linefeed. The key is, remove the linefeed (0xa) character after the name, will likely solve you problem. |
|||
18 Jun 2023, 11:42 |
|
asmblr_88 18 Jun 2023, 21:09
I applied your advice, and it worked. My brain is still trying to comprehend it.
Studying the hexdump also helped a lot as well. Since I am not using a constant that counts characters automatically (such as $-input_name), I have to know the exact number of characters I will be inputting when prompted. Since I put John, and John is 4 characters, I reserved 4 bytes for the response variable and it allows a period at the end. But I reserved 16 bytes for the name variable, and if I were to type Johnny, it would only print John since I have not written any line to offset it I guess. I am going to try to implement a macro to see if it works maybe. I will post the edited version in case anyone needs it for future reference. Thanks everyone, have a great night!
|
|||||||||||
18 Jun 2023, 21:09 |
|
asmblr_88 18 Jun 2023, 21:16
Also redsock, I wasn't aware that I could use eax and rax registers in the same program. Is it because rax is an extension of eax?
Also when you say return, do you mean when popping off the stack, putting the exit code in it or the success code? I will update the program soon when I have the time to follow along with your recommendations of putting each instruction into which registers they belong in. Thanks again! |
|||
18 Jun 2023, 21:16 |
|
redsock 18 Jun 2023, 22:52
When you know for certain that you only need 32 bits, it is perfectly safe and sane to use the 32 bit registers in your 64bit program. Things like syscall numbers and file descriptors are guaranteed to be < 32 bits.
Code: mov eax, 1 xor ecx, ecx By "return in rax/eax", I mean syscall returns themselves. Your call to the read syscall returns the number of bytes read and 0 if EOF, or <0 on error (noting EINTR is not really an error but needs to be handled as well). Similarly, your call to the write syscall returns the number of bytes written. |
|||
18 Jun 2023, 22:52 |
|
Flier-Mate 18 Jun 2023, 23:38
Assigning syscall number to eax is shorter than to rax.
Code: 0: 48 c7 c0 01 00 00 00 mov rax,0x1 7: b8 01 00 00 00 mov eax,0x1 2 bytes shorter in the assembled binary. |
|||
18 Jun 2023, 23:38 |
|
asmblr_88 19 Jun 2023, 13:32
I feel like I am learning a lot more incrementally.
Thanks to everyone for your patience and explanations. I appreciate it. I feel as though I am learning a little bit more on how the processor works, especially when it comes to processing information as a stream of bytes. It makes me appreciate and understand just how fast the processor is working. It is helping me to visualize it more easily than before. _________________ asmblr_88 |
|||
19 Jun 2023, 13:32 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.