flat assembler
Message board for the users of flat assembler.

Index > OS Construction > How to add some spaces to string

Author
Thread Post new topic Reply to topic
gangsta-dogg



Joined: 11 Sep 2007
Posts: 6
gangsta-dogg 02 Oct 2007, 15:03
How to add some spaces to string?
I have filename rb 13, filename = "file1" or any, how to add some spaces and get 11 len string(FAT 12 FS)

sorry for my bad english Smile
Post 02 Oct 2007, 15:03
View user's profile Send private message Reply with quote
Mac2004



Joined: 15 Dec 2003
Posts: 314
Mac2004 02 Oct 2007, 17:17
Your english is ok, so there is no need to be sorry for that! Smile

You could use second buffer filled with spaces. Then just copy the original string to the new buffer and there you have the filename patched with spaces.

regards,
Mac2004
Post 02 Oct 2007, 17:17
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 02 Oct 2007, 18:04
So you should use capitals letters, and put space to make the name up to 8 or 11, if there is no extension, so file1 would be written as
Code:
filename db "FILE1      "    

and file1.bin as
Code:
filename db "FILE1   BIN"    
Post 02 Oct 2007, 18:04
View user's profile Send private message Reply with quote
gangsta-dogg



Joined: 11 Sep 2007
Posts: 6
gangsta-dogg 02 Oct 2007, 19:09
Quote:
You could use second buffer filled with spaces. Then just copy the original string to the new buffer and there you have the filename patched with spaces.

please give me some code sample

Quote:
So you should use capitals letters, and put space to make the name up to 8 or 11, if there is no extension, so file1 would be written as filename db "FILE1 ", filename db "FILE1 BIN"

this method is not right for my code, I get filename string from keyboard

And I have another problem: I write some GOS(real-time OS), and it's work, I load bin program from kernel to adress 0800h:0000h and jump to this code, it's works, but I can't return to kernel ORG 1600h adress... help me please...
Post 02 Oct 2007, 19:09
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4352
Location: Now
edfed 02 Oct 2007, 23:33
you can make a call far and then a ret far
or jmp to the kernel address like you jmp to bin

be sure that your stack don't override the kernel code too
Post 02 Oct 2007, 23:33
View user's profile Send private message Visit poster's website Reply with quote
gangsta-dogg



Joined: 11 Sep 2007
Posts: 6
gangsta-dogg 03 Oct 2007, 08:21
Quote:

you can make a call far and then a ret far
or jmp to the kernel address like you jmp to bin

thanks for help
Post 03 Oct 2007, 08:21
View user's profile Send private message Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel 03 Oct 2007, 10:25
Quote:
this method is not right for my code, I get filename string from keyboard

It should work even if you get the filename from the keyboard and it contains a dot between the name and the extension. It's straightforward, you just have to use string manipulation instructions or the usual cmp and mov instructions to change the input string into a FAT12 filename.

eg:
1. you get the filename from the user (eg: "File.asm");
2. you UPCASE each character and copy them from there to your buffer until you find a dot (eg: "FILE");
3. you skip the dot; if your buffer is not already 8 bytes long, you pad it with spaces until it is (eg: "FILE ");
4. you UPCASE the first 3 characters after the dot (the extension) and copy them right after the padding (eg: "FILE ASM").

You can also check if there is no extension as Dex4u said. You can begin your search for the extension dot from the end of the filename instead of the beginning so that you wouldn't use parts of the name as an extension if the user typed a dot in his filename (eg: "file.1.asm"); you'd end up with "FILE 1.a" instead of "FILE.1 ASM".
Post 03 Oct 2007, 10:25
View user's profile Send private message Reply with quote
gangsta-dogg



Joined: 11 Sep 2007
Posts: 6
gangsta-dogg 03 Oct 2007, 14:01
Quote:

1. you get the filename from the user (eg: "File.asm");
2. you UPCASE each character and copy them from there to your buffer until you find a dot (eg: "FILE");
3. you skip the dot; if your buffer is not already 8 bytes long, you pad it with spaces until it is (eg: "FILE ");
4. you UPCASE the first 3 characters after the dot (the extension) and copy them right after the padding (eg: "FILE ASM").

please give me code sample
Post 03 Oct 2007, 14:01
View user's profile Send private message Reply with quote
Mac2004



Joined: 15 Dec 2003
Posts: 314
Mac2004 03 Oct 2007, 19:18
gangsta-dogg: Here's a short (untested) example what I meant. I hope this helps.... Smile

Code:

        ;clear destination buffer
      ;------------------------

       mov bx,destination_buf          ;get secondary buffer ptr
   mov cx,11                       ;clear 11 characters

clear:
      mov byte[bx],' '              ;fill up with space char
    inc bx 
     loop clear                      ;do 11 chars 


       ;copy the source filename to the destination buffer
 ;---------------------------------------------------

    mov si,source_name              ;get source ptr
     mov di,destination_buf          ;get destination ptr
        mov cx,11                       ;11 charcaters is the max
copy:
      mov al,byte[si]                 ;get a byte from the source
 cmp al, 0                       ;is this the end of the source str?
 jz done
     mov byte[di],al                 ;save the byte into the destination str
     inc si
      inc di
      loop copy


done:


destination_buf: times 13 db 0
source_name:         db "FILE1",0         

     
Post 03 Oct 2007, 19:18
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 03 Oct 2007, 19:30
gangsta-dogg wrote:
Quote:

1. you get the filename from the user (eg: "File.asm");
2. you UPCASE each character and copy them from there to your buffer until you find a dot (eg: "FILE");
3. you skip the dot; if your buffer is not already 8 bytes long, you pad it with spaces until it is (eg: "FILE ");
4. you UPCASE the first 3 characters after the dot (the extension) and copy them right after the padding (eg: "FILE ASM").

please give me code sample


See the source code of MiniDos, it will do all that ManOfSteel listed.
http://board.flatassembler.net/topic.php?t=5275&start=0
Post 03 Oct 2007, 19:30
View user's profile Send private message Reply with quote
gangsta-dogg



Joined: 11 Sep 2007
Posts: 6
gangsta-dogg 04 Oct 2007, 06:55
Quote:

gangsta-dogg: Here's a short (untested) example what I meant. I hope this helps.... Smile

yea, now i'ts works, big thanks!

Quote:

See the source code of MiniDos, it will do all that ManOfSteel listed.

ok, thanks Dex4u!
MiniDOS source is realy help me too...
P.S. DexOS - is good project, respect!
Post 04 Oct 2007, 06:55
View user's profile Send private message Reply with quote
Mac2004



Joined: 15 Dec 2003
Posts: 314
Mac2004 04 Oct 2007, 17:12
gangsta-dogg: I'am glad to help! Smile

regards,
Mac2004
Post 04 Oct 2007, 17:12
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.