Created
September 12, 2016 03:17
-
-
Save rseymour/9ae3c144d7a60455270ae700b404156e to your computer and use it in GitHub Desktop.
simple.asm with more comments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; a simple hello world .COM | |
; compile with: yasm -o simple.com simple.asm | |
; Ange Albertini, BSD Licence, 2013 | |
; w/ some dummy comments by Rich Seymour | |
org 100h ; standard loaded address | |
bits 16 ; ouch :p | |
DISPLAY_STRING equ 9h ; 9h is DISPLAY_STRING equ means equals foreva, 9h is an interrupt to display | |
TERMINATE_WITH_RETURN_CODE equ 4ch ; same. interrupt to return from program | |
MAIN_DOS_API equ 21h ; aka the main dos interrupt | |
; in a .COM file, DATA is with mixed with CODE | |
; not strictly required, as by default, ds=cs on initialization, but safer | |
; cs: code segment, ds: data segment | |
push cs ; store cs on sp, the stack pointer | |
pop ds ; pop the sp into ds, the data segment | |
; print("Hello World!\r\n\r") | |
; now remember mov moves right to left | |
; I still haven't found a reason for Intel syntax being right to left. | |
; But other parts of it make a lot more sense. you could perhaps think of this as mov to dx from msg | |
; the other syntax AT&T has its own problems so we needn't concern ourselves with it | |
mov dx, msg ; msg defined at the end is stored in data register DX (ax,bx,cx,dx were the 4 16 bit registers) | |
mov ah, DISPLAY_STRING ; store the interrupt to actually display a string | |
int MAIN_DOS_API ; this calls the dos api to do what's in AH | |
; return 1; | |
ERRORCODE equ 1 | |
mov ax, (TERMINATE_WITH_RETURN_CODE << 8) | ERRORCODE | |
int MAIN_DOS_API ; similar as above, but AX because AH has the 4ch and the errorcode is down in AL | |
msg db 'Hello World!', 0dh, 0dh, 0ah, '$' ; DOS string are $-terminated. db is a pseudo op to 'assemble' bytes into a variable |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment