[Solved] Calculation problem

Programming, for all ages and all languages.
Post Reply
User avatar
Masterkiller
Member
Member
Posts: 153
Joined: Sat May 05, 2007 6:20 pm

[Solved] Calculation problem

Post by Masterkiller »

I know it is probably a silly question, but I lose a lot of time and still cannot handle it.

Code: Select all

XOR eax, eax	;Clear EAX for calculation
MOV al, dh	;Load the accumulator with start row
MOV cx, 80	;Load cx with 80 because MUL require source
MUL cl		;Multiply by Screen Width - result is a word in AX
MOV cl, dl	;Load cx with the column
ADD ax, cx	;Adding the column to the result
MOV cl, 2	;Multiply the result by two because
MUL cl		;every symbol is two bytes - one ASCII and one attribute
ADD eax, 0xB8000	;Adding base address of Video Mem
This should be calculate the address of Video Memory for a position stored in BH and BL, but it appears that the start position is moved only by X. I load in BX 1010h and CALL my function, but text appears on the 1st line, 16th column, instead of 16th line, 16th colimn... Where do I mistake?

P.S. Sorry for the bad english :oops:
Last edited by Masterkiller on Sat Dec 15, 2007 1:36 pm, edited 1 time in total.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

This should be calculate the address of Video Memory for a position stored in BH and BL
Then, would you mind using bl/bh instead of dl/dh?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Masterkiller
Member
Member
Posts: 153
Joined: Sat May 05, 2007 6:20 pm

Post by Masterkiller »

Solved it. Just like the post for division. It appears that MUL cl (MSVC shows this as MUL al, cl) does not return the result in ax, but in al and wrap if needed. Very strange but... MUL by 16-bit source evaluate everything properly :)
Post Reply