this is the relevant code. it SHOULD put a character in edx to the screen and increment the column variable by 1 but it does nothing. can anyone see what I'm don't wrong?
terminal_row db 0
terminal_column db 0
putc:
mov eax, terminal_row
mov ebx, 80
mul ebx
add eax, terminal_column
mov ebx, 2
mul ebx
add eax, 0xB8000
mov byte[eax], dl
mov bx, terminal_column
inc bx
mov terminal_column, bx
ret
can't get my putc function to put a c
- BASICFreak
- Member
- Posts: 284
- Joined: Fri Jan 16, 2009 8:34 pm
- Location: Louisiana, USA
Re: can't get my putc function to put a c
Your code seem right and should place the character with no problem other than:
The color attribute seems to be 0x00 (black on black)
Mul overwrites both eax and edx (so your dl is probably not what you think it is [dl=0x00?])
Also to optimize it a little do a bit shift, do not multiply (unless you multiply by a variable and not a constant)
The color attribute seems to be 0x00 (black on black)
Mul overwrites both eax and edx (so your dl is probably not what you think it is [dl=0x00?])
Also to optimize it a little do a bit shift, do not multiply (unless you multiply by a variable and not a constant)
BOS Source Thanks to GitHub
BOS Expanded Commentary
Both under active development!
BOS Expanded Commentary
Both under active development!
Sortie wrote:
- Don't play the role of an operating systems developer, be one.
- Be truly afraid of undefined [behavior].
- Your operating system should be itself, not fight what it is.
Re: can't get my putc function to put a c
i have already set the color of all the characters in the buffer to 7. and yes i realized what I was doing so I push edx at the begninning now and pop it at the end right before I use it. still no good
Re: can't get my putc function to put a c
If this is written for NASM/YASM or FASM, you need square brackets around memory operands that you read or write. You only have them in one out of five places.
-
- Member
- Posts: 501
- Joined: Wed Jun 17, 2015 9:40 am
- Libera.chat IRC: glauxosdever
- Location: Athens, Greece
Re: can't get my putc function to put a c
Hi,
Here is the code (untested). Let us know if it works.
You should check if terminal_column is above or equal to 80. If so, reset terminal_column and increment terminal_row (don't let it go to next row automatically, because terminal_column will overflow). You should also check if terminal_row is above or equal to 25. If so, you should scroll.
Regards,
glauxosdever
Here is the code (untested). Let us know if it works.
Code: Select all
terminal_row db 0
terminal_column db 0
putc:
; in: dl=char, cl=color
movzx eax, byte [terminal_row] ; For terminal_row you have defined 1 byte, but eax is 4 bytes wide
movzx ebx, byte [terminal_column] ; We are going to use it later
imul eax, 80*2 ; There are 80 chars per row but each char takes 2 bytes
add eax, ebx ; Add columns of last row two times
add eax, ebx ; because each char takes 2 bytes
mov byte [0x000B8000 + eax], dl ; Write char
mov byte [0x000B8001 + eax], cl ; Write color
inc byte [terminal_column] ; Go one column right
ret
Regards,
glauxosdever
- xenos
- Member
- Posts: 1121
- Joined: Thu Aug 11, 2005 11:00 pm
- Libera.chat IRC: xenos1984
- Location: Tartu, Estonia
- Contact:
Re: can't get my putc function to put a c
Note that your code trashes EBX, so if you call it from C code, you should save and restore it.glauxosdever wrote:Here is the code (untested).