![]() |
![]() |
![]() |
The MOV mnemonic
This (finally) is where we learn to use our first assembler mnemomic - MOV. As you can imagine from the name, it's purpose is to move a value from one place to another. At the present state of our project, we have the width stored in the string "clientDimensions" but now we want to append the comma and space - ", ". We can actually move these two characters directly into one of our 32-bit registers. In fact, we could move 4 characters at a time, if we wanted, since each character occupies 8 bits.
The question is - which register should we use? We might be tempted to use the EAX register. It's a fairly popular one but it's currently holding some information which is very important to us - can you remember what it is? When we converted the width to a string, the EAX register returned from the String function with the number of characters making up the new string. We need this information because we don't want to put the ", " at the beginning of clientDimensions. We want to "skip" into the string by the length of the width string and place it there. OK. Let's use the EBX register. The MOV mnemonic requires us to specify first the target and then the source of the data, separated by a comma. To move the string ", " into EBX, all we have to say is:
Mov Ebx, ", "
Easy or what?
But now comes the hard part. We need to move what's in EBX to the location in memory where clientDimension is stored plus whatever is in EAX (the width of the string generated earlier). Since we are storing it in a box, we should use the square brackets. This is how we wouold express it:
Mov [clientDimensions + Eax], Ebx
So you can see that we can perform a little arithmetic inside the square brackets to indicate an "offset" from the base address of the "variable". Place these two lines after your "Invoke String" instruction and recompile. You should now see your width in the caption bar, followed by a comma. The code so far looks like this:
OnResize:
UseData winMainProcedure
Invoke GetClientRect, [hWnd], Addr clientRect
Invoke String, [clientRect.right], Addr clientDimensions, ecDecimal
Mov Ebx, ", "
Mov [clientDimensions + Eax], Ebx
Invoke SetText, [hWnd], Addr clientDimensions
Return (TRUE)
EndU
; End OnResize
To complete our handler, all that remains is to calculate where the end of the string now is and then to convert the height of the client area to string and then append it at that location within clientDimensions. One way to work out the new location for the next string is to take what we already have - EAX (holding the width of the first string) - add the address of the clientDimensions variable and then add a further 2 places to take care of the ", ". To do this, we use another mnemonic - ADD.
![]() |
![]() |
![]() |