NASM - The Netwide Assembler
NASM Forum => Programming with NASM => Topic started by: yoran on May 13, 2018, 04:45:13 PM
-
I want to do the following, let's say we have a string called A and it contains 'echo Hello, World!'
I want to do this:
reverse A, now it is '!dlrow ,elloH ohce'
remove the last 5 chars, so it is '!dlrow, elloH'
reverse A, so it is 'Hello, World!'
and output A, because the user inputted A in the first place in a, it is for a command prompt, so that is why the echo is there.
I can do the reversing, but I can't seem to figure out how to remove the last 5 chars from the string.. does anyone know how to do this?
It is bare bones (no int21h) and Bits 16.
-
Count 'em? I'm not sure I see the "issue" here. Zero-terminated string? Do you really want to remove 5 characters exactly, or "to the first space"? Is there some point to reversing it and then reversing it again? Do you propose to replace the "removed" characters with spaces? Zeros? Or can you just re-terminate the string? Seems like it should be a simple question, but we may need more information. Where do you get stuck?
Best,
Frank
-
I basically have a command line, I want to be able to type 'ECHO HELLO, WORLD!', and it to repeat everything except 'ECHO '. If there is any other way, I will be happy to know!
-
We really don't know what you've got so far. I suppose something like...
mov si, prompt
call print
mov cx, BUFSIZ
mov di, buffer
call ngets ; please don't reinvent gets!
; ...
Now I suppose you want to see if the pesky user has typed a known command or not. Besides "ECHO", "REBOOT" is an easy one. "DIR" needs a lot more code.
If it's "ECHO" (need to be uppercase?)... suppose di is still pointing to the space...
lea si, [buffer + di] ; +1?
call print
That should about do it. Of course, I've left out a few details. I don't know how you want to do it. since I don't know what you've got so far...
Best,
Frank
-
(no delete comment option, so I'll do this)
-
I FOUND IT!
What is now do is, when I want to check for echo, is I'm going to split the command into ECHO and everything else.
DI = everything else, so mov [parameters], di, check if SI is echo, and if so:
echo_cli:
mov WORD si, [parameters]
cmp si, 0
je cmd
int 80h ;print
jmp cmd
-
Does it work? Seems unlikely... You only put two bytes into si - "he" perhaps...
Best,
Frank
-
input_buffer = ECHO HELLO, WORLD!
backup_buffer = input_buffer
>ECHO (removed)
split |
>HELLO, WORLD! (di)
parameters = DI
check
yes? echo_cli
echo_cli:
mov WORD si, [parameters] ;HELLO, WORLD!
cmp si, 0 ;so not empty
je cmd
int 80h ;print SI, so HELLO, WORLD!
jmp cmd
-
mov WORD si, [parameters] ;HELLO, WORLD!
This will put two bytes - the characters 'H' and 'E' - into si. I don't see how this could possibly cause "HELLO, WORLD!" to be printed, which is what I understand you want.
More likely(?) you want the address of parameters...
mov WORD si, parameters ; 16 bit address of HELLO, WORLD!
Linux uses int 80h. The subfunction that prints text expects an address in ecx. But I unfrstood you were using a "bare bones" system. It is quite possible to install code at int 80h which prints text at the address in si ... or the "[contents"], but that would only be two bytes. Is this what you've done? We really don't know...
Best,
Frank
-
parameters is defined as following:
parameters dw 0
I tested this, and it works.
-
Okay. If it works, it works!
Best,
Frank
-
Anyway, thanks for helping!