assembly - ASCIIZ string ending with a zero byte -


i writing assembly level program create file.

.model small .data  fn db "test"  .code mov ax,@data  mov ds,ax  mov cx,00 lea dx,fn  mov ah,3ch int 21h  mov ah,4ch 21h end 

although program had no errors, file not created, searched internet getting reason.

then found asciiz.

so replaced data segment with

.data fn db "test", 0  

it worked.

why need use asciiz , why can't normal string used create file?

let's have multiple string .data section:

fn db "test"  s1 db "aaa" s2 db "bbb" 

when compile it, .data section have 3 strings in it, 1 after other:

0x74 0x65 0x73 0x74 0x61 0x61 0x61 0x62 0x62 0x62 

which binary representation testaaabbb.

there must way functions figure out first string ends , second begins. "marker" 0x00 byte ( "\x00" ), know "null byte terminated string" or asciiz, way can know string ending:

fn db "test",0 s1 db "aaa",0x00 ; same s2 db "bbb\x00" ; still same thing 

now .data section looks this

0x74 0x65 0x73 0x74 0x00 0x61 0x61 0x61 0x00 0x62 0x62 0x62 0x00 

which test\x00aaa\x00bbb\x00and have delimited between strings when provide starting address of string function, know string ends.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -