flat assembler
Message board for the users of flat assembler.

Index > Main > Effective memory addressing problem-Strings

Author
Thread Post new topic Reply to topic
vargadanis



Joined: 09 Feb 2008
Posts: 9
vargadanis 09 Feb 2008, 12:16
Hi

I have a code like this:

Code:
msg db 'Why u dont work?', 0
msg_len db $-msg    


And I would like to write each byte of the msg to certain memory locations one by one.
Eg:
The first byte og the msg (containing the hex for W ASCII) would go to 0xb800:0x00
and the second to 0xb800:0x02
and so on...
How do I do that?
Post 09 Feb 2008, 12:16
View user's profile Send private message MSN Messenger Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4353
Location: Now
edfed 09 Feb 2008, 12:55
like you said

first byte to 0b8000h
second to 0b8002h
etc...

an instruction is needed:
mov
Post 09 Feb 2008, 12:55
View user's profile Send private message Visit poster's website Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto 09 Feb 2008, 13:26
Code:
msg db 'Why u dont work?', 0 

@Print:

    PUSH    ES

      PUSH    0B800H          ; Segment Memory Video
      XOR     DI,DI
       POP     ES
  MOV     SI,msg          ; Load OFFSET String
@@:
     MOV     AL,[SI]         ; Load Byte From String
     OR      AL,AL           ; End Of String ?
   JZ      @End

    MOV     [ES:DI],AL  ; Write Byte
        ADD     DI,2
        ADD     SI,1
        JMP     @B

@End:
 POP     ES
  RET
    


Note: On windows Xp console mode set video mode before to
write, or make a dummy read using int 10h ah 0fh
Post 09 Feb 2008, 13:26
View user's profile Send private message Reply with quote
vargadanis



Joined: 09 Feb 2008
Posts: 9
vargadanis 09 Feb 2008, 13:52
Yeah.. it doesn't work. I used the exact same code here and there was no output for the code when i booted it up. I am getting angry at this whole asm thing.
I chkd out the video memory and it was a mess but not what we wanted...
Let's go a little bit basic...

How do I refer to the first byte of the msg?
Post 09 Feb 2008, 13:52
View user's profile Send private message MSN Messenger Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto 09 Feb 2008, 13:58
try this on xp or win 98 console mode
Code:
ORG 100H

    MOV     AX,0003H
    INT     10H
 CALL    @Print

  XOR     AX,AX
       INT     16H

     RET

@Print: 

        PUSH    ES 

        PUSH    0B800H          ; Segment Memory Video 
        XOR     DI,DI 
        POP     ES 
        MOV     SI,msg          ; Load OFFSET String 
@@: 
        MOV     AL,[SI]         ; Load Byte From String 
        OR      AL,AL           ; End Of String ? 
        JZ      @End 

        MOV     [ES:DI],AL      ; Write Byte 
        ADD     DI,2 
        ADD     SI,1 
        JMP     @B 

@End: 
        POP     ES 
        RET


msg db 'Why u dont work?', 0 
    


compile FASM msg.asm
Please post your example
Post 09 Feb 2008, 13:58
View user's profile Send private message Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4353
Location: Now
edfed 09 Feb 2008, 14:03
easy:
your message is at [data segment:msg].
the text screen is at 0b800h
the first char is at [text screen:0]
so, to put a char on the screen at boot:
Code:
org 7c00h
mov ax,cs
mov ds,ax
mov ss,ax  
mov ax,0b800h
mov es,ax
mov si,msg
mov di,0
mov ah,[color]
@@:
mov al,[si]
cmp al,0
je @f
inc si
mov [es:di],ax
add di,2
jmp @b
@@:
jmp $
msg db 'message to print at boot',0
colr db 71h  ;blue text on grey background
rb 510-($-$$)
dw 0aa55h
    

compile, copy to bootsector of a drive and reboot!
Post 09 Feb 2008, 14:03
View user's profile Send private message Visit poster's website Reply with quote
DJ Mauretto



Joined: 14 Mar 2007
Posts: 464
Location: Rome,Italy
DJ Mauretto 09 Feb 2008, 14:10
You need a bootcode Question
I did not understand what you are trying to do,
my code works fine ,but it is for dos,win98 or Xp
Post 09 Feb 2008, 14:10
View user's profile Send private message Reply with quote
vargadanis



Joined: 09 Feb 2008
Posts: 9
vargadanis 09 Feb 2008, 14:24
Is it important at all where the msg db is located? I mean in the end or in the beginning of the file? What does jmp $ exactly doing?

One more thing that I am not sure about (FASM syntax):
how is it possible to jump to @f label if only @@-s are defined?
Post 09 Feb 2008, 14:24
View user's profile Send private message MSN Messenger Reply with quote
vargadanis



Joined: 09 Feb 2008
Posts: 9
vargadanis 09 Feb 2008, 14:25
DJ Mauretto wrote:
You need a bootcode Question
I did not understand what you are trying to do,
my code works fine ,but it is for dos,win98 or Xp


That could be... sorry for being asxxxle
Post 09 Feb 2008, 14:25
View user's profile Send private message MSN Messenger Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4353
Location: Now
edfed 09 Feb 2008, 15:29
jmp $= jmp to jmp
it means:
there:
goto there

for @@:
if no @@: is defined after @f, it don't works.
@f is the reference to the following @@:, the next one
@b is a refenrence to @@: before.
Post 09 Feb 2008, 15:29
View user's profile Send private message Visit poster's website Reply with quote
vargadanis



Joined: 09 Feb 2008
Posts: 9
vargadanis 09 Feb 2008, 15:40
smart Smile I don't think there is such thing in NASM. I do stuff mostly in NASM but getting familiar with FASM as well. I really like the advanced syntax
Post 09 Feb 2008, 15:40
View user's profile Send private message MSN Messenger Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4353
Location: Now
edfed 09 Feb 2008, 16:37
did you read the fasm.PDF file?
all is explained into.
take one or two hours, read this, and begin the enjoyment.
Post 09 Feb 2008, 16:37
View user's profile Send private message Visit poster's website Reply with quote
vargadanis



Joined: 09 Feb 2008
Posts: 9
vargadanis 10 Feb 2008, 12:39
U think that fasm is so much more enjoyable than any other? I am just wondering not accusing
Post 10 Feb 2008, 12:39
View user's profile Send private message MSN Messenger Reply with quote
Alphonso



Joined: 16 Jan 2007
Posts: 295
Alphonso 10 Feb 2008, 17:51
Something like..
Code:
org 100h         ;or format MZ

push cs          ;
pop ds           ;incase you want a .exe

mov ax,0b800h    ;
mov es,ax        ;Set up ES: for text

mov ax,3         ;
int 10h          ;set up video mode for B800

mov si,msg       ;Start of msg
mov di,0         ;top left position on the screen
mov ah,9fh       ;background / foreground color
mov cx,msg_len   ;length of message

@@: lodsb        ;get byte in al from DS:SI and inc SI by 1
    stosw        ;store word in ax to ES:DI and inc DI by 2
    loop @b      ;Dec cx, jump to @@ until cx 0

mov ax,1         ;
int 16h          ;wait for keypress
int 20h          ;old style exit

msg db 'Why u dont work?'
msg_len=$-msg     
Post 10 Feb 2008, 17:51
View user's profile Send private message Reply with quote
vargadanis



Joined: 09 Feb 2008
Posts: 9
vargadanis 10 Feb 2008, 19:38
Wow...
U did a really good job on commenting ur code which is to be honest very clean. Makes it enjoyable to read. Smile
Post 10 Feb 2008, 19:38
View user's profile Send private message MSN Messenger 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.