Author Topic: Hello World  (Read 3168 times)

Offline Structure

  • Jr. Member
  • *
  • Posts: 21
Hello World
« on: December 11, 2019, 04:03:35 PM »
.zeroTerminated:
Code: [Select]
times 512-($-$$) db 0
jmp start

print:
 pusha
 .printloop:
   mov al, [si]
   cmp al, 0
   jne .printchar
   popa
   ret
 .printchar:
   mov ah, 0x0e
   int 0x10
   add si, 1
   jmp .printloop
ret

string: db "Hello World.", 0

start:
  mov si, string
  call print
« Last Edit: December 11, 2019, 04:20:31 PM by Structure »

Offline debs3759

  • Global Moderator
  • Jr. Member
  • *****
  • Posts: 98
  • Country: gb
    • GPUZoo
Re: Hello World
« Reply #1 on: December 11, 2019, 09:42:16 PM »
.zeroTerminated:
Code: [Select]
times 512-($-$$) db 0
jmp start

print:
 pusha
 .printloop:
   mov al, [si]
   cmp al, 0
   jne .printchar
   popa
   ret
 .printchar:
   mov ah, 0x0e
   int 0x10
   add si, 1
   jmp .printloop
ret

string: db "Hello World.", 0

start:
  mov si, string
  call print

In your code, if that is the entire code, $ = $$ (both are at the start of your code). So

times 512-($-$$) db 0

inserts 512 0 bytes at the start of the code. What is that for?
My graphics card database: www.gpuzoo.com

Offline Structure

  • Jr. Member
  • *
  • Posts: 21
Re: Hello World
« Reply #2 on: December 11, 2019, 10:06:25 PM »
The first 512 kb are reserved for the boot sector:

https://en.wikipedia.org/wiki/Boot_sector

or a file header, etc...
« Last Edit: December 11, 2019, 10:08:07 PM by Structure »

Offline debs3759

  • Global Moderator
  • Jr. Member
  • *****
  • Posts: 98
  • Country: gb
    • GPUZoo
Re: Hello World
« Reply #3 on: December 11, 2019, 11:13:17 PM »
I did wonder if this was related to a boot sector, but it wasn't obvious from your code. My FAT12 boot sector code is lower down in this forum :)
My graphics card database: www.gpuzoo.com

Offline T145

  • Jr. Member
  • *
  • Posts: 12
  • Country: 00
  • Hacker, Jacker & All-Around Gobsmacker
    • CodeReview
Re: Hello World
« Reply #4 on: December 13, 2019, 04:42:44 AM »
You don't need any of that bootcode, since you're not making anything to boot into, like a virtual floppy disk. As you know, in 16 bit land we just start executing from the top, so you can always just use the following macro to print your string:

Code: [Select]
%macro puts 1
    pushaw
    mov     si, %1
    mov     ah, 0Eh    ; INT 10h doesn't trash ah or bx
    mov     bx, 7      ; video mode support
%%read:
    lodsb
    test    al, al     ; check for null-terminating character (0)
    jz      %%done
    int     10h        ; print character in al
    jmp     %%read
%%done:
    popaw
%endmacro

Then just `puts string` and either `ret` or `jmp $` to avoid running into the data section.

Offline Structure

  • Jr. Member
  • *
  • Posts: 21
Re: Hello World
« Reply #5 on: January 02, 2020, 05:21:42 PM »
rebuild:

Code: [Select]
string: db "Hello World", 0
%macro print 1
    mov si, %1
    %%char_loop:
        mov cl, [si]
        inc si
        cmp cl, 0 
        je  %%exit_loop
        mov al, cl
        mov ah, 0x0e
        int 0x10
    call %%char_loop
  %%exit_loop:
%endmacro
print string
jmp $

 8)
« Last Edit: January 07, 2020, 11:48:56 AM by Structure »

Offline michaellongge

  • New Member
  • Posts: 1
Re: Hello World
« Reply #6 on: June 08, 2020, 06:52:14 PM »
cant run on win7

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2451
  • Country: us
Re: Hello World
« Reply #7 on: June 09, 2020, 02:42:43 AM »
No. int 0x10 is BIOS code.  It is 16 bit code.

If you want something for Windows, look into WriteFile.

Best,
Frank