assembly - In NASM labels next to each other in memory are causing printing issues -


i having issue while programming in nasm. learning how develop os purely in assembly , have started creating boot loader.

my goal print "hello, world!" , "goodbye!" using the bios interrupt 0x10.

the issue seem having occurs while printing values on screen. 2 labels appear next each other in memory causing printing 1 string print contents of other string.

why isn't hlen stopping loop @ end of first string?

    [org 0x7c00]      mov ah, 0x0e      mov bx, hello_msg     mov cx, hlen                                                                                                                                                   call print_string      mov bx, goodbye_msg     mov cx, glen                                                                                                                                                   call print_string      jmp $      %include "print_string.asm"       hello_msg db 'hello, world!',0     goodbye_msg db 'goodbye!',0       hlen equ $ - hello_msg     glen equ $ - goodbye_msg      times 510-($-$$) db 0     dw 0xaa55 

bugs:

  1. prints goodbye message twice

    this due hello_msg printing hello, world! , goodbye!. believe occurs because hello_msg label right next goodbye_msg label in memory

;;;print_string.asm print_string:                   ;cx = string length                                                                                                                                                                                           ;bx = string label - memory offset                                                                                                                                                        ; -- if want data @ memory adress use [bx]                                                                                                                                 mov al, [bx]         int 0x10          inc bx          loop print_string          ret 

your computation of hlen includes string goodbye! because comes after defintion of goodbye_msg. expression $ - hello_msg number of bytes between label hello_msg , line hlen defined. why first call print_string prints both messages.

try order instead:

hello_msg db 'hello, world!',0 hlen equ $ - hello_msg  goodbye_msg db 'goodbye!',0 glen equ $ - goodbye_msg 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -