Guest User

Untitled

a guest
Jan 23rd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .model  small                   ; 64k data and 64k code
  2. .8086                           ; only allow 8086 instructions
  3. ;---------------------------------------
  4. .data
  5. ;---------------------------------------
  6. PREV    db      4Eh             ; Lots of
  7. msga    db      'LABEL='        ; "booleans,"
  8. LBL     db      4Eh             ; by which
  9. msgb    db      '  OPCODE=' ; I mean
  10. OPCODE  db      4Eh             ; "variables
  11. msgc    db      '  OPER1='      ; functioning
  12. OPER1   db      4Eh             ; as booleans"
  13. msgd    db      '   OPER2=' ; The messages
  14. OPER2   db      4Eh             ; are offset to
  15. msge    db      '   COMMENT='   ; print
  16. CMMT    db      4Eh             ; everything
  17. term    db      13,10,'$'       ; all at once.
  18. ;---------------------------------------
  19. .code
  20. ;---------------------------------------
  21. start:
  22.         mov     ax,@data        ; establish addressability
  23.         mov     ds,ax           ; for the data segment
  24.         mov     bx,0            ; clear index register
  25. getchar:
  26.         mov     ah,8            ; read without echo a character
  27.         int     21h             ; how: set ah=8 and issue int 21h
  28.         mov     cl,al           ; save the character (cl=xy)
  29. eoftest:
  30.         cmp     cl,1Ah          ; EOF?
  31.         je      exit            ; GTFO!
  32. newlinetest:
  33.         cmp     cl,0Dh          ; Newline?
  34.         je      print           ; Print current booleans, go to the next line
  35.  
  36. skip:
  37.         cmp     [CMMT],59h      ; Is there a comment?
  38.         je      stuff           ; Jump to stuff
  39. iscolon:
  40.         cmp     cl,3Ah          ; Is it a colon?
  41.         jne     iscomma         ; Jump to comma stuff.
  42. colon:
  43.         mov     [LBL],59h       ; Label = yes
  44.         mov     [OPCODE],4Eh    ; Reset OPCODE because spaces are stupid
  45. iscomma:
  46.         cmp     cl,2Ch          ; Dat comma?
  47.         jne     isop            ; ...nope.
  48. datcomma:
  49.         mov     [OPER1],59h     ; Operand 1 = yus
  50.         mov     [OPER2],59h     ; Operand 2 = HYES
  51. isop:
  52.         cmp     PREV,20h        ; is prev a space?
  53.         jne     issemi          ; Go on
  54.         cmp     cl,20h          ; If you currently have a space
  55.         je      stuff           ; Go on
  56.         cmp     cl,3Bh          ; Or a semicolon
  57.         je      semicolon       ; In which case, go to that
  58. ops:
  59.         cmp     cl,41h          ; If current is less than the value of 'A'
  60.         jb      issemi          ; then skip this stuff.
  61. isopcode:
  62.         cmp     [OPCODE],59h    ; If opcode is NO
  63.         jne     other           ; Go set op1 to YES
  64.         mov     [OPER1],59h     ; Set op1 to YES
  65.         jmp     issemi          ; Next!
  66. other:
  67.         mov     [OPCODE],59h    ; Set it to YES
  68. issemi:
  69.         cmp     cl,3Bh          ; How 'bout a semicolon?
  70.         jne     stuff           ; You got yerself a comment.  Jump!
  71. semicolon:
  72.         mov     [CMMT],59h      ; Comment = yesh
  73. stuff:
  74.         mov     [PREV],cl       ; Transfer the current char to "PREV"
  75.         mov     dl,cl           ; transfer it to the data segment for printing
  76.         mov     ah,02h          ; write the character
  77.         int     21h             ; how: set ah=2 and issue int 21h
  78.         jmp     getchar         ; loop back to beginning until a line finishes
  79.        
  80. print:
  81.         mov     dl,cl           ; Echo the line feed
  82.         mov     ah,02h          ; Set to print
  83.         int     21h             ; Interrupt
  84.        
  85.         mov     ah,8            ; Get the next
  86.         int     21h             ; character
  87.        
  88.         mov     dl,al           ; Each the carriage return
  89.         mov     ah,02h          ; Set to print
  90.         int     21h             ; Interrupt
  91.        
  92.         mov     dx,offset msga  ; Prepare to write a string
  93.         mov     ah,9            ; Set DOS to write a string
  94.         int     21h             ; Interrupt
  95.        
  96.         mov     [LBL],4Eh       ; Reset
  97.         mov     [OPCODE],4Eh    ; all
  98.         mov     [OPER1],4Eh     ; of
  99.         mov     [OPER2],4Eh     ; the
  100.         mov     [CMMT],4Eh      ; things!
  101.         jmp     getchar         ; Go all the way back
  102. ;---------------------------------------
  103. ;Exit sequence, when no characters remain
  104. ;---------------------------------------
  105. exit:
  106.         mov     dx,offset term  ; Store the newline
  107.         mov     ah,9            ; Set to print
  108.         int     21h             ; Interrupt
  109.         mov     dl,1Ah          ; Set the SUB character
  110.         mov     ah,02h          ; Ready to print
  111.         int     21h             ; Interrupt
  112.         mov     ax,4c00h        ; set the correct exit code in ax
  113.         int     21h             ; int 21h will terminate program
  114.         end     start           ; execution begins at the label start
  115. ;---------------------------------------
Add Comment
Please, Sign In to add comment