# Author: Susam Pal <http://susam.in/>
#
# To assemble and link this code, execute:-
# as -o string.o string.s
# ld --oformat binary -Ttext 7c00 -Tdata 7c20 -o string string.o
#
# To write this code into the boot sector of a device, say /dev/sdb:-
# dd if=string of=/dev/sdb
# echo -ne "\x55\xaa" | dd seek=510 bs=1 of=/dev/sdb

.code16

.section .data
message:
  .asciz "hello, world"

.section .text
.globl _start
_start:
  nop
  xor %di, %di
  mov $0xb800, %ax
  mov %ax, %ds
  mov $message, %si
move:
  xor %dx, %dx
  mov %cs:(%si), %dl
  cmp $0, %dl
idle:
  jz idle
  mov %dl, (%di)
  inc %di
  movb $0x1e, (%di)
  inc %di
  inc %si
  jmp move 
