Skip to content

Instantly share code, notes, and snippets.

@vmxdev
Created July 11, 2022 10:57
Show Gist options
  • Select an option

  • Save vmxdev/cc7bc0674524959caff5164f8ef0717d to your computer and use it in GitHub Desktop.

Select an option

Save vmxdev/cc7bc0674524959caff5164f8ef0717d to your computer and use it in GitHub Desktop.
8086 16-bit helloworld in GNU assembly
# as --32 hello.s -o hello.o
# ld -melf_i386 -Ttext=0x100 --oformat=binary hello.o -o hello.com
.code16
.globl _start
.section .text
_start:
# print question
movw $ask, %dx
movb $0x09, %ah
int $0x21
# input string
movw $name, %dx
movb $0x0a, %ah
int $0x21
# append '$' to the end of user string
movw $name + 2, %bx
addb (nmlen), %bl
movb $'$', (%bx)
# put ", " between 'Hello' and user input
movw $0x202c, %ax
movw %ax, (name)
# print 'Hello, %user-input'
movw $msg, %dx
movb $0x09, %ah
int $0x21
ret
ask: .ascii "What is your name? $"
msg: .ascii "\nHello"
name: .byte 0xff # allow up to 255 symbols
nmlen: .byte 0 # input string length
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment