Simple MASM program


/ Published in: Assembler
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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
  7.  
  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.
  15.  
  16.  
  17. .code
  18. _start:
  19. mov ax,03h ;clears screen (function 3h)
  20. int 10h ;interrupt 10h
  21.  
  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
  27.  
  28. mov ah,01h ;function 01h of int21h,
  29. int 21h ;get char from keyboard
  30.  
  31. cmp al, "Y" ;if ah Y then
  32. je Yes ;Goto Yes label
  33.  
  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
  37.  
  38. Yes:
  39. mov ax,03h ;clears screen (function 3h)
  40. int 10h ;interrupt 10h
  41.  
  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
  48.  
  49. No:
  50. mov ax,03h ;clears screen (function 3h)
  51. int 10h ;interrupt 10h
  52.  
  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
  59.  
  60. close:
  61. mov ax,4c00h ;put 4c00h into ax, closing back to DOS
  62. int 21h ;INT 21h, return to DOS
  63.  
  64. end _start

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.