i have got piece of code runs in realmode , printf message on screen,i using dosbox 0.7 execution environment .below code
jmp 0x7c0:start start: mov ax, cs ; set segments mov ds, ax mov es, ax mov al,03h mov ah,0 int 10h welcome db "this insane now" mov si, welcome call print_string print_string: lodsb ; grab byte si or al, al ; logical or al jz .done ; if result zero, out mov ah, 0x0e int 0x10 ; otherwise, print out character! jmp print_string .done: ret
i able assemble code fine when run ,it hangs there , message can see in linux terminal
illegal read b0671921, cs:ip 7c0: 4468
this how assembling it
nasm print.asm -o out.com
i have tried searching message in google , found problem dosbox version.
can let me know problem here??
the problem code place of string constant. must placed never "executed" because not code.
another issue how code ends. boot record should load other code (os kernel, or bigger boot program) , jump it. or @ least (if want test something) make infinite loop. in case, program falls print_string subroutine , tries "return" nowhere.
here fixed version:
org 7c00h start: mov ax, cs ; set segments mov ds, ax mov es, ax mov al, 03h mov ah, 0 int 10h mov si, welcome call print_string .sleep: jmp .sleep print_string: lodsb ; grab byte si test al, al ; logical or al jz .done ; if result zero, out mov ah, 0x0e int 0x10 ; otherwise, print out character! jmp print_string .done: ret welcome db "this insane now", 0
why jump removed? bios, after loading boot sector disk, places on address 0000h:7c00h. respectively, jumps $0000:$7c00 in order start execution of code.
as long (probably) inial code compiled @ offset $0000, first jump changes segment 7c0h , offset 0000h in order provide proper execution of program.
but can set origin of our program 7c00h (org 7c00h) , way avoid using 1 more instruction.
Comments
Post a Comment