Last question failed, got a tougher one ... - TechRepublic
Question
November 22, 2011 at 10:21 PM
dhcdbd

Last question failed, got a tougher one …

by dhcdbd . Updated 14 years, 7 months ago

In the last post I asked a question about the use of a C++ break statement inside a for loop and an if statement. It failed. What I needed was a continue statement. However, I rewrote the lines so that a continue statement was not needed.

Now I want to write part of that block of code as assembly language.

This is the block of code I want to write as assembly:
if (triggerType == SLIDER || triggerType == HSLIDER)
values = slider;
else
values = axis;

This is the block of inline assembly that I came up with:
__asm{
push ebp ;// save callers stack frame
mov esp, ebp ;// establish new stack frame
sub esp, 4 ;// allocate local data space of 4 bytes
push esi ;// save critical registers
push edi ;//
push eax ; //

//move data to compare into register
mov eax, triggerType ;// move triggerType into eax
cmp eax, SLIDER ;// compare triggerType == Slider
je VLues ;// if true, jump to set value
cmp eax, HSLIDER ;// compare triggerType == HSLIDER
je VLues ;// if true, jump to set values
mov values, axis ;// else set default values
jmp BYE ;// jump to clean up route and set stack back up

VLues:
mov values, slider ;

BYE:
pop eax ; ;// clean up stack and restore
pop edi ;
pop esi ;
add esi , 4 ;
mov ebp, esp ;
pop ebp ;
}

Something tells me that the block of assembly is not correct and I can’t put my finger on it. Because this code will operate at ring 0, I cannot run it assembled until I am certain that it is correct.

Does anyone have any input on where I might be going wrong?

This discussion is locked

All Comments