(Assembler) Simple MASM program

This demonstrates a simple “Hello World” style program for 16-bit (DOS) x86 assembly using Microsoft’s free MASM assembler.

  1. .model small
  2. .stack
  3. .data
  4. Message db "Press Y or N:$" ;Prompt for user
  5. Uyes db "You pressed Y!$" ;Pressed y
  6. Uno db "You pressed N!$" ;Pressed n
  8. ;how to do assembly:
  9. ;download masm32
  10. ;download link563.exe (extracts link.exe)
  11. ;replace c:\masm32\bin\link.exe with THAT link.exe
  12. ; use ml /c /coff blah.asm
  13. ;  then    link blah.obj
  14. ; when it asks you for blah.exe  just keep hitting enter.
  17. .code
  18. _start:
  19. mov ax,03h ;clears screen (function 3h)
  20. int 10h ;interrupt 10h
  22. mov ax, SEG Message ;put segment of message into AX
  23. mov ds, ax ;put this into DS
  24. mov dx, OFFSET Message ;put offset of message into AX
  25. mov ah,09h ;Function 9h of
  26. int 21h ;Interrupt 21h
  28. mov ah,01h ;function 01h of int21h,
  29. int 21h ;get char from keyboard
  31. cmp al, "Y" ;if ah Y then
  32. je Yes ;Goto Yes label
  34. cmp al, "N" ;if ah N then
  35. je No ;Goto No Label
  36. jne _start ;if not Y or N then goto start
  38. Yes:
  39. mov ax,03h ;clears screen (function 3h)
  40. int 10h ;interrupt 10h
  42. mov ax, SEG Uyes ;segment of Uyes
  43. mov ds, ax ;put segment into DS
  44. mov dx, OFFSET Uyes ;put offset of Uyes into DX
  45. mov ah,09h ;function 9h print string at DS:DX
  46. int 21h ;call interrupt 21h
  47. jmp close
  49. No:
  50. mov ax,03h ;clears screen (function 3h)
  51. int 10h ;interrupt 10h
  53. mov ax, SEG Uno ;segment of Uno
  54. mov ds, ax ;put segment into DS
  55. mov dx, OFFSET Uno ;put offset of Uno into DX
  56. mov ah,09h ;function 9h print string at DS:DX
  57. int 21h ;call interrupt 21h
  58. jmp close
  60. close:
  61. mov ax,4c00h ;put 4c00h into ax, closing back to DOS
  62. int 21h ;INT 21h, return to DOS
  64. end _start
This entry was posted in Assembler and tagged , , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Why ask?