Here I created the code for writing ASCII characters to VGA memory:
.global _put_in_mem _put_in_mem: push bp mov bp, sp mov cx, [bp + 4] mov si, [bp + 6] mov bx, 0xb800 mov ds, bx mov [si], cx add bx, 0x1 mov cx, 0x7 mov [si], cx pop bp ret
This is called through the kernel.c file shown below:
void main() { extern void put_in_mem(); char c = 'e'; put_in_mem(c, 0xA0); }
The above code is for printing "e" at the beginning of the second line in QEmu, but it is not. I tried debugging this with gdb and found that the command
mov bx, 0xb800
in gdb has become
mov -0x4800,%bx
and the value in ebx after this command is 0x0.
Why is the value not loaded into the bx register?
In addition, I thought that move instructions use the ds register as the base of their segments and remove all addresses from the contents of ds. Therefore, according to these considerations, I suggested that when
mov [si], cx
The contents of the cx register will be located at 0xb8a0. It's right? Can the mov instruction affect any other segregation registers (e.g. cs, es, etc.)?
source share