Following the baby steps tutorial, why does this code work?
Posted: Tue Oct 23, 2012 2:40 pm
Hi, another noob here, so sorry if I'm not to quick to grasp some stuff, (don't worry I know some basic OS theory though, I'm not coming here from nothing). Anyway, I've been following the babystep tutorials on the wiki (which are very good by the way, thankyou whoever wrote them), and have reached number 4. The code inside it is pretty basic, and I understand most of it, however there are a few lines in the printreg16 "function" that I don't understand. Here is the code for people to look at: http://wiki.osdev.org/Babystep4
I could just copy and paste the lines in, but I somehow doubt that will help me learn. The lines are these
rol ax, 4
mov bx, ax
and bx, 0x0f
mov bl, [si + bx]
mov [di], bl
this is part of a loop that loops for 4 times (1 for each character, as 16 bit registers have 4 digits when written in hex) and the register we are attempting to print's higher byte is the color attribute, and it's lower byte is the character.
My question is, too get the hex value of the character, why does the lines that I have pasted work. I know what each individual instruction does, but I can't seem to figure why that would find the hex value of the character. Can anyone tell me why.
I could just copy and paste the lines in, but I somehow doubt that will help me learn. The lines are these
rol ax, 4
mov bx, ax
and bx, 0x0f
mov bl, [si + bx]
mov [di], bl
this is part of a loop that loops for 4 times (1 for each character, as 16 bit registers have 4 digits when written in hex) and the register we are attempting to print's higher byte is the color attribute, and it's lower byte is the character.
My question is, too get the hex value of the character, why does the lines that I have pasted work. I know what each individual instruction does, but I can't seem to figure why that would find the hex value of the character. Can anyone tell me why.