Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .model small ; 64k data and 64k code
- .8086 ; only allow 8086 instructions
- ;---------------------------------------
- .data
- ;---------------------------------------
- PREV db 4Eh ; Lots of
- msga db 'LABEL=' ; "booleans,"
- LBL db 4Eh ; by which
- msgb db ' OPCODE=' ; I mean
- OPCODE db 4Eh ; "variables
- msgc db ' OPER1=' ; functioning
- OPER1 db 4Eh ; as booleans"
- msgd db ' OPER2=' ; The messages
- OPER2 db 4Eh ; are offset to
- msge db ' COMMENT=' ; print
- CMMT db 4Eh ; everything
- term db 13,10,'$' ; all at once.
- ;---------------------------------------
- .code
- ;---------------------------------------
- start:
- mov ax,@data ; establish addressability
- mov ds,ax ; for the data segment
- mov bx,0 ; clear index register
- getchar:
- mov ah,8 ; read without echo a character
- int 21h ; how: set ah=8 and issue int 21h
- mov cl,al ; save the character (cl=xy)
- eoftest:
- cmp cl,1Ah ; EOF?
- je exit ; GTFO!
- newlinetest:
- cmp cl,0Dh ; Newline?
- je print ; Print current booleans, go to the next line
- skip:
- cmp [CMMT],59h ; Is there a comment?
- je stuff ; Jump to stuff
- iscolon:
- cmp cl,3Ah ; Is it a colon?
- jne iscomma ; Jump to comma stuff.
- colon:
- mov [LBL],59h ; Label = yes
- mov [OPCODE],4Eh ; Reset OPCODE because spaces are stupid
- iscomma:
- cmp cl,2Ch ; Dat comma?
- jne isop ; ...nope.
- datcomma:
- mov [OPER1],59h ; Operand 1 = yus
- mov [OPER2],59h ; Operand 2 = HYES
- isop:
- cmp PREV,20h ; is prev a space?
- jne issemi ; Go on
- cmp cl,20h ; If you currently have a space
- je stuff ; Go on
- cmp cl,3Bh ; Or a semicolon
- je semicolon ; In which case, go to that
- ops:
- cmp cl,41h ; If current is less than the value of 'A'
- jb issemi ; then skip this stuff.
- isopcode:
- cmp [OPCODE],59h ; If opcode is NO
- jne other ; Go set op1 to YES
- mov [OPER1],59h ; Set op1 to YES
- jmp issemi ; Next!
- other:
- mov [OPCODE],59h ; Set it to YES
- issemi:
- cmp cl,3Bh ; How 'bout a semicolon?
- jne stuff ; You got yerself a comment. Jump!
- semicolon:
- mov [CMMT],59h ; Comment = yesh
- stuff:
- mov [PREV],cl ; Transfer the current char to "PREV"
- mov dl,cl ; transfer it to the data segment for printing
- mov ah,02h ; write the character
- int 21h ; how: set ah=2 and issue int 21h
- jmp getchar ; loop back to beginning until a line finishes
- print:
- mov dl,cl ; Echo the line feed
- mov ah,02h ; Set to print
- int 21h ; Interrupt
- mov ah,8 ; Get the next
- int 21h ; character
- mov dl,al ; Each the carriage return
- mov ah,02h ; Set to print
- int 21h ; Interrupt
- mov dx,offset msga ; Prepare to write a string
- mov ah,9 ; Set DOS to write a string
- int 21h ; Interrupt
- mov [LBL],4Eh ; Reset
- mov [OPCODE],4Eh ; all
- mov [OPER1],4Eh ; of
- mov [OPER2],4Eh ; the
- mov [CMMT],4Eh ; things!
- jmp getchar ; Go all the way back
- ;---------------------------------------
- ;Exit sequence, when no characters remain
- ;---------------------------------------
- exit:
- mov dx,offset term ; Store the newline
- mov ah,9 ; Set to print
- int 21h ; Interrupt
- mov dl,1Ah ; Set the SUB character
- mov ah,02h ; Ready to print
- int 21h ; Interrupt
- mov ax,4c00h ; set the correct exit code in ax
- int 21h ; int 21h will terminate program
- end start ; execution begins at the label start
- ;---------------------------------------
Add Comment
Please, Sign In to add comment