Answer the question
In order to leave comments, you need to log in
Assembler, do I understand correctly that the default registers are 0x00?
All good. I'm trying to learn assembler. There is an example with two subroutines.
; library.asm
int 0x20
; display on the screen the letter that is written in the AL register (in ASCII code)
display_letter:
push ax
push bx
push cx
push dx
push si
push di
mov ah, 0x0E ; function code that displays a letter on the screen
mov bx, 0x000F ; 00 - zero page; BL - letter color
int 0x10 ; we turn to the BIOS so that it draws the letter
pop di
pop si
pop dx
pop cx
pop bx
pop ax
ret
; reads a character from the ASCII keyboard and puts it in AL
read_keyboard:
push bx
push cx
push dx
push si
push di
mov ah, 0x00 ; function code that reads a character from the keyboard
int 0x16 ; we turn to the BIOS to execute it
pop di
pop si
pop dx
pop cx
pop bx
ret
I have not yet reached the study of push, pop from the stack, but I roughly imagine that in this way register values \u200b\u200bthat change during the execution of the subroutine are reserved. In the display_letter subroutine, the AX, BX registers are reserved because they are changed directly during the execution of the subroutine to call interrupt 0x10.
But in the read_keyboard subroutine, for some reason, they do not save the AX register and save the BX register, which does not seem to change directly in the subroutine. And if we accept the fact that by default the value 0x00 is stored in the registers and, accordingly, the AX register does not change, then why do we need to additionally write 0x00 to AH before calling interrupt 0x16? I tried not to write anything to the AH register and cause an interrupt 0x16, which means the default is in the 0x00 register. And that's why they kept the BX register - I did not understand where it is and how it changes.
Answer the question
In order to leave comments, you need to log in
And if we accept the fact that by default the value 0x00 is stored in the registers
I tried not to write anything to the AH register and cause an interrupt 0x16, which means the default is in the 0x00 register.
in the read_keyboard subroutine, for some reason, they do not save the AX case
why they saved the BX register - I did not understand
No, registers are used by different processes, the kernel, and so on. If you haven't reset them yourself, they can contain anything.
I recommend that you definitely look at the documentation in order to clearly understand which registers use the input data, and where the result is placed.
push and pop in this case are used to save register values and then restore them. However, called functions DO NOT use these registers. And save/restore doesn't make any sense.
int 10
0eH write character to active video page (TTY emulation)
input: AL = character being written (uses existing attribute)
BL = foreground color (for graphics modes)
display_letter:
mov ah, 0x0E ; код функции которая выводит букву на экран
mov bx, 0x000F ; 00 - нулевая страница; BL - цвет буквы
int 0x10 ; обращаемся к BIOS, чтобы она нарисовала букву
read_keyboard:
mov ah, 0x00 ; код функции считывающей символ с клавиатуры
int 0x16 ; обращаемся к BIOS чтобы выполнить ее
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question