How would I display the string that the user entered?
And I need to display it at the center of a 80x25 text screen with the following formula:
column = (80 - string length) / 2;
row = 25/2;
.MODEL TINY
.386
STACK 256
DATASEG
msg db 'Enter string:$'
sbuf label word ;адрес буфера для функции 0Ah
max db 0 ;максимальное количество символов
len db 0 ;количество фактически введенных
string db 254 DUP('#') ;буфер для строки (адрес строки)
;string db 255,0, 256 dup (' ')
new db 0ah, 0dh, '$'
CODESEG
start:
mov ax,@data
mov ds,ax
mov ah,09h
mov dx,offset msg
int 21h
mov ah, 0Ah
mov dx,offset string
int 21h
xor ax,ax
mov al,offset string+1
inc dx
add dx, ax
mov si,dx
mov ah,09h
mov dx,offset new ;output new line symbol
int 21h
std ;устанавливаем флаг направления дляпрохода обратно
print_next_char:
lodsb ;читаем символ из DS:SI и уменьшаем SI на 1
cmp si,offset string+1 ;конец строки? (то есть начало)
jb endprog ; если да, то переход к концу программы
cmp al,0dh
je skip
cmp al,023h
je skip
movzx bx,al
dec bx
inc byte[bx+len]
skip:
mov dl, al ;загружаем прочитанный из строки символ в DL
mov ah,02h ;DOS-функция вывода символа
; int 21h ;вызов DOS
jmp print_next_char ;возвращаемся к следующему символу
endprog:
mov dx,offset new
mov ah,09h
int 21h
mov DX, OFFSET string ; ds:dx points to string
mov AH, 09h
int 21h
mov AX, 4C00h ; Return to DOS with ERRORLEVEL=0
int 21h
end start
My task is to develop an executable (EXE) program, which initially displays (function 09h, DOS 21h interrupt) an invitation to enter a string of characters from the keyboard.
After entering (function 0Ah, DOS 21h interrupt) line, the program should display its string centered on the screen (function 13h, BIOS 10h interrupt). The coordinate of the screen position where the output has to be put is calculated as follows:
column = (80 - dlina_stroki) / 2;
row = 25/2;
To enter the string you can define the following buffer:
; ...
.data
; ...
sbuf label word ; buffer address 0Ah function
max db 0 ; the maximum number of characters
len db 0 ; the number is actually imposed
string db 254 dup (0) ; buffer line (row address)
; ...
Then, in the program of each of the referenced sbufs of the buffer, it can be used as separate variables.