Advertisement
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
- .stack 256 ; stack size is 256 bytes
- ;---------------------------------------
- .data
- ;---------------------------------------
- asmln DB 50 dup(' ')
- opcode DB 'opCode = $'
- lab DB 'label = $'
- opHolder DB 5 dup ('F')
- opVal DB 5 dup ('N')
- oper1 DB 'oper1 = $'
- oper2 DB 'oper2 = $'
- comment DB 'comment = $'
- holdb DB 0
- infile DB 'sample.in'
- outfile DB 'sample.out'
- mhandle DW ' '
- CR equ 13d
- LF equ 10d
- ;---------------------------------------
- .code
- ;---------------------------------------
- ; Establish addressability to the data segment.
- ; Initialize the work register.
- ; - bx is cleared to zero and will be used as
- ; an index register in the conversion process
- ;---------------------------------------
- start: ;
- mov ax,@data ; establish addressability
- mov ds,ax ; for the data segment
- mov si, offset asmln
- ;---------------------------------------
- ; Try to read from the keyboard.
- ; - program only terminates when a period
- ; is read from the keyboard)
- ;---------------------------------------
- getChar: ;
- mov ah, 8h ; read without echo a character
- int 21h
- mov [si], al
- add si, 1
- cmp al, 0Dh
- je printString
- postPrint:
- ;------Start of main control loop
- ; mov si, offset asmln
- cmp al, 1Ah
- je exit
- cmp al, 1Ah ;compare [letter] and ','
- jne getChar ; if letter not a '.' jump to getChar
- printString:
- mov [si], al
- add si, 1
- mov ah, 8
- int 21h
- mov [si], al
- mov si, offset asmln
- printChar:
- mov ah, 2
- mov dl,[si]
- int 21h
- add si, 1
- mov bl, 0Ah
- cmp [si], bl
- jne printChar
- ;-- attempt to add newline
- mov dl, 0Ah
- mov ah, 2
- int 21h
- mov si, offset asmln
- call mainblock
- mov si, offset asmln
- call resetVar
- jmp postPrint
- mainblock:
- call comCheck
- mov ah, 2
- mov di, offset opVal
- mov dl, [di]
- int 21h
- ; call printnl
- call labelCheck
- mov ah, 2
- mov di, offset opVal
- add di, 4
- mov dl, [di]
- int 21h
- ; call printnl
- ;--------------------------------
- call opCheck
- mov ah, 2
- mov di, offset opVal
- add di, 1
- mov dl, [di]
- int 21h
- call printnl
- ;--------------------------
- ret
- comCheck:
- mov si, offset asmln
- cCheck:
- mov bl, 3Bh
- cmp [si], bl
- je setopVal
- mov bl, 0Ah
- cmp [si],bl
- je retreturn
- add si, 1
- mov bl, 3Bh
- cmp [si], bl
- ; add si, 1 ; this line is from above
- jne cCheck
- ;-- placement for opvalue change
- setopVal:
- mov di, offset opVal
- mov cx, 'Y'
- mov [di], cx
- add di, 1
- ret
- labelCheck:
- mov si, offset asmln
- lCheck:
- mov bl, 0Ah
- cmp [si], bl
- je retreturn
- add si, 1
- mov bl, 3Ah
- cmp [si], bl
- jne lCheck
- mov di, offset opVal
- mov cx, 'Y'
- add di, 4
- mov [di], cx
- ret
- opCheck:
- mov di, offset opVal
- ; add di, 1
- mov bl, 'Y'
- cmp [di], bl
- je isLab
- mov bl, 3Bh
- cmp [si], bl
- je retreturn
- call cl_white_space
- cmp [si], bl
- jne setopcode
- ret
- isLab:
- mov si, offset asmln
- call cl_white_space
- call cl_char
- call cl_white_space
- mov bl, 3Bh
- cmp [si], bl
- je retreturn
- setopcode:
- mov di, offset opVal
- add di, 1
- mov cx, 'Y'
- mov [di], cx
- ret
- ret
- retreturn:
- ret
- printnl:
- mov dl, 0Ah
- mov ah, 2
- int 21h
- ret
- resetVar:
- mov cx, 5
- mov di, offset opVal
- resetpt:
- mov dx, 'N'
- mov [di], dx
- add di, 1
- loop resetpt
- ret
- incsi:
- add si, 1
- cl_white_space:
- mov bl, 20h
- white_space:
- cmp [si], bl
- je incsi
- ret
- skip_char:
- add si, 1
- cl_char:
- mov bl, 3Ah
- check_char:
- cmp [si], bl
- jge skip_char
- ret
- ;---------------------------------------
- ; The user typed a period so terminate.
- ;---------------------------------------
- exit: ;
- mov ax,4c00h ; set correct exit code in ax
- int 21h ; int 21h will terminate program
- end start ; execution begins at the label start
- ;---------------------------------------
- #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement