Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Computer Architectures (02LSEOV)
- ; Problem n. 2
- ;https://911programming.wordpress.com/2010/05/14/emu8086-read-a-string-from-keyboard/
- ;http://www.fysnet.net/kbbuffio.htm
- ;https://eclass.upatras.gr/modules/document/file.php/EE649/8086%20Registers.htm
- DIM EQU 40h;64 bytes
- MIN_L EQU 14h; 20 chars min
- MAX_L EQU 32h;50 chars max
- CAE_K EQU 03h;Caesar cipher K
- .MODEL small
- .STACK
- ;;data segment: it will contain the four arrays
- .DATA
- FIRST_ROW DB DIM DUP(?)
- SECOND_ROW DB DIM DUP(?)
- THIRD_ROW DB DIM DUP(?)
- FOURTH_ROW DB DIM DUP(?)
- prompt_str DB 'Please enter a string:$'
- oob_str DB 'Input out of bounds!$'
- ;;code segment
- .CODE
- .STARTUP
- ;;Prepare buffers: buffer[0] must be equal to buffer size.
- mov AH, DIM
- mov FIRST_ROW[0], AH
- mov SECOND_ROW[0], AH
- mov THIRD_ROW[0], AH
- mov FOURTH_ROW[0], AH
- ;;Acquire inputs
- lea DX, FIRST_ROW;get address of first row in DX
- call input_row
- call print; print first row
- .EXIT
- ;;Inputs acquired.
- ;retrieves user input into a buffer, which is passed as the argument
- ; input_row( DX = buffer, )
- PROC input_row NEAR
- push BP
- mov SP, BP
- push AX
- push BX
- push SI
- ;print input prompt
- lea DX, prompt_str
- call print
- ;initialize counter for input'd chars to 0
- mov CL, 0
- ;use SI as base address for the string
- mov SI, DX
- ;use BX as a pointer from the base address of the string
- mov BX, 0
- ;INT 21 AL 1: get single char, then display it
- input_loop:
- mov AH, 1
- INT 21h;result is stored in AL
- ;Check it is not return
- ;Which would indicate the end of input
- cmp AL,13; 13 = RETURN
- je check_length
- ;Store input'd character in the string
- mov [SI][BX], al
- ;Move the pointer 1 position forward
- inc BX
- check_length:
- input_row_end:
- pop SI
- pop BX
- pop AX
- pop BP
- ret
- ;return values
- ;1st byte of the buffer = buffer size
- ;2nd byte of the buffer = string length (input'd characters)
- ENDP
- ;prints a string.
- ; print( DX = buff )
- PROC print NEAR
- push bp
- mov sp, bp
- push ax
- mov ah, 9
- int 21h
- pop ax
- pop bp
- ret
- ENDP
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement