Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Sorry if i wrote stupid code
I am just learning asm and i want to write a 'a' at a line i choose in PMode
pop ax ;Pop line
shl ax, 41 ;Line * 80 * 40
xor di, di ;Zero
mov di, ax ;Set line
mov ax, 0B8000h ;Screen mem !To big
mov si, ax ;Set screen
mov ah, 'a' ;Put a in ax
mov si:[di], ah ;Write char in mem !wrong
inc di ;Next byte
mov ah, 0x07 ;Set attr
mov si:[di], ah ;Write attr in mem !wrong
NO!!!
the upper part of EAX could have any value in it!
to ensure that EAX has the same value as AX
clear EAX
mov eax,0
before you assign a value to AX
mov ax,XXXX
now EAX will have same value as AX because
the top part has been filled with ZERO
top EAX bottom EAX
AX
00000000XXXXXXXX
xor eax,eax is faster than mov eax,0 because with xor eax,eax the computer has only to tranfer the operation-code over the system-bus. With mov eax,0 ist first transfers the opcode of mov eax,? and then it transfers the parameter of this operation (in this case it is 0). Another advantage of xor eax,eax is that it is 1 Byte smaller than mov eax,0. (I hope that's right). So your kernel will be one byte bigger if you use mov eax,0, but nowadays this shouldn't matter.
Why? In things like the BootSector, one byte means alot, so if you could save a byte, why not?
Also, as for speed, i'm not saying that you should spend hours speed optimizing the code, but if you can add a few tweaks that'll save some load time, then why not?
You can perform any multiplication in asm using multiple combitions of SHL and ADD. It's just a question of when the SHL/ADD technique takes up more cycles than the MUL. This varies from processor to processor, MUL is definitely getting to be faster than it used to be. Division of course is an entirely different proposition, if you aren't dividing by 2^X then techniques start to get quite complicated and it's usually better handled by the hardware.
BTW, if you're working in asm it's far handier to be able to do hex maths in your head than decimal or binary.