flat assembler
Message board for the users of flat assembler.

Index > Main > how get the length of a string in a src

Author
Thread Post new topic Reply to topic
MAD_DËMON



Joined: 03 Mar 2006
Posts: 23
MAD_DËMON 04 May 2006, 23:38
Image

plz how can i calculate the size of any string? i need it to work with the Write String func in the BIOS INT 10h

_________________
Tah rah rah boom de ay, I blew some guy away, his brains turned into spray, I was paid well that day
Post 04 May 2006, 23:38
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 04 May 2006, 23:52
place the following code before any string definition:
Code:
struc db [chars]
{ 
common 
    . db chars
    .size = $ - .
}    


Then you can use it this way: mov cx, PideNumDIgits.size

[edit]I see a bug in your code, you must place the the function number in AH, not AL, so use "mov ax, $1300" or "mov ah, $13". Also check http://www.ctyme.com/intr/rb-0210.htm to see what you prefer in AL, maybe you want to use "mov ax, $1301"[edit]
Post 04 May 2006, 23:52
View user's profile Send private message Reply with quote
saigon



Joined: 29 May 2006
Posts: 62
saigon 12 Jun 2006, 19:01
@locodelassembly: Is there any other way?
I thought something like this, but it doesn't work:

mov cx, $-chars

Can you help me get that to work? Thanks!

EDIT: Ofcourse it doesn't work, because $ means "here", so I can't do that..
Post 12 Jun 2006, 19:01
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 12 Jun 2006, 19:56
Here an example for DOS
Code:
struc db [chars]
{  
common  
    . db chars 
    .size = $ - . 
}

struc String [chars] ; As Turbo Pascal
{
common
  .size db 0
  .chars db chars
  store $ - .chars at .size
}
STDOUT equ 1

org 100h

mov ah, $40
mov bx, STDOUT
mov cx, message.size
mov dx, message
int $21

mov ah, $40
mov bx, STDOUT
mov cl, [pascalMessage.size]
mov dx, pascalMessage.chars
int $21

xor ax, ax
int $16

int $20

message db "Hello World!!", 13, 10

pascalMessage String "And now a Pascal hello world!!", 13, 10    


You can see a new Pascal-style string. Why do you need a different way?

Regards

PS: The db struc in my source is the same that the one explained in the FASM's manual, I think

[edit]Changed "STDOUT equ 2" 2 to "STDOUT equ 1". 2 is STDERR...[/edit]


Last edited by LocoDelAssembly on 12 Jun 2006, 20:53; edited 1 time in total
Post 12 Jun 2006, 19:56
View user's profile Send private message Reply with quote
saigon



Joined: 29 May 2006
Posts: 62
saigon 12 Jun 2006, 20:20
Nice example!
I wanted to have the size stored only for one string instead for all of them.
Post 12 Jun 2006, 20:20
View user's profile Send private message Reply with quote
RedGhost



Joined: 18 May 2005
Posts: 443
Location: BC, Canada
RedGhost 16 Jun 2006, 08:47
saigon wrote:
Nice example!
I wanted to have the size stored only for one string instead for all of them.


Code:
name db 'xxx', 0
name.size = $-name
    

_________________
redghost.ca
Post 16 Jun 2006, 08:47
View user's profile Send private message AIM Address MSN Messenger Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner 16 Jun 2006, 10:34
[unrelated]
if you guys like the font MAD_DËMON used, check here
http://www.dafont.com/font.php?file=bitstream_vera_mono

i just knew this font from MAD_DËMON through pm, thanks!
Post 16 Jun 2006, 10:34
View user's profile Send private message Visit poster's website 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.