Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;========================================================================;
- ;Authored by H4x0 ;
- ;Using samples from the 'blackfireize' Youtube tutorial series ;
- ;http://www.youtube.com/watch?v=GFkrYM7mbTc ;
- ;http://www.h4x0.com/lib/Snippets/Tutorial_Notes.asm ;
- ;16Bit Assembly (DOS) - emu8086 & FASM ;
- ;========================================================================;
- #fasm#
- name "mycode"
- org 100h ;DOS FTW!
- call one ;Used for calling a function or "label"
- ;Change to lesson function you want to see
- call return_os ;Call our helper function to return control
- ;to the operating system
- ;========================================================================;
- ;Variables ;
- ;========================================================================;
- msgOne db 'Hello World$' ;Define a string called msgOne
- msgThr db 'Look At Source$'
- ;========================================================================;
- ;Lesson functions ;
- ;========================================================================;
- one:
- mov ah, 9h
- mov dx, msgOne ;Move msgOne to dx register
- int 21h ;Print (Execute interupt)
- ret ;Return from function
- two:
- mov ax, 123d ;Move 123 (Integer) to ax register
- call print_decimal ;Call the print_decimal helper function
- ret ;Return from function
- three:
- ;Informational Lesson
- ;AX ;Acumulator Register (Mathmatical Operations)
- ;AH ;A (Register) H (High)
- ;AL ;A (Register) L (Low)
- ;BX ;Base Register (Counting, Manipulation, General)
- ;BH ;B (Register) H (High)
- ;BL ;B (Register) L (Low)
- ;CX ;Unknown Name (Counting Operations)
- ;CH ;C (Register) H (High)
- ;CL ;C (Register) L (Low)
- ;DX ;Data Register (Holding Memory or Data Pointers)
- ;DH ;D (Register) H (High)
- ;DL ;D (Register) L (Low)
- ;Segment Registers (Point to 64kb memory segments)
- ;CS ;Code Segment
- ;DS ;Data Segment
- ;ES ;Extra Segment
- ;FS ;Extra Segment
- ;GS ;Extra Segment
- ;SS ;Stack Segment
- ;ESI ;Extended Source Index
- ;SI ;Source Index (String Operations)
- ;EDI ;Extended Destination Index
- ;DI ;Destination Index (General Purposse)
- ;EBP ;Extended Base Pointer
- ;BP ;Base Pointer
- ;ESP ;Extended Stack Pointer
- ;SP ;Stack Pointer
- ;EFLAGS ;Never Change (at least directly)
- ;FLAGS ;Never Change (at least directly)
- ;ZF ;Zero Flag
- ;PF ;Parody Flag
- mov ah, 9h
- mov dx, msgThr ;Move msgThr to dx register
- int 21h ;Print (Execute interupt)
- ret ;Return from function
- ;========================================================================;
- ;Helper functions ;
- ;========================================================================;
- return_os: ;Return control to OS
- mov ah, 4ch
- int 21h ;Execute interupt
- print_decimal: ;AX -> Decimal Number
- pusha ;Push all to the stack
- mov bx, 10d ;Move 10 (Integer) to bx register
- mov cx, 0 ;Move 0 (Integer) to cx register
- mov dx, 0 ;Move 0 (Integer) to dx register
- .tryloop1: ;Loop
- inc cx ;Register cx++ or cx=cx+1 (Increment)
- mov dx, 0 ;Move 0 (Integer) to dx register
- div bx ;Divide bx register
- push dx ;Push dx to stack
- cmp dx, 0 ;Compare dx register with 0
- jne .tryloop1 ;Jump back if not equal
- mov ah, 02h
- .tryloop2: ;Loop
- pop dx ;Clear dx register
- add dl, 48 ;Get ASCII char from integer by adding 48
- int 21h ;Print (Execute interupt)
- loop .tryloop2 ;
- popa ;Pop all from stack
- ret ;Return from function
Advertisement
Add Comment
Please, Sign In to add comment