Web Development



Last question failed, got a tougher one ...

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;
values = axis;

This is the block of inline assembly that I came up with:
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

mov values, slider ;

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 conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Answers

Collapse -

Partial answer.

by DHCDBD In reply to Last question failed, got ...

This code block has an error:
mov values, slider ;

The error is also further up in this block:
mov values, axis ;// else set default values

The Visual Studio inline assembler does not allow direct memory moves, if any assembly compiler does.

The proper method to address this problem is:
mov eax, slider ;
mov values, eax;

Or in the second example:
mov eax, axis ;// else set to default values
mov values, eax ;// cant directly move memory to memory

Replacing just the referenced If/else statement with assembly increased the speed of an XBox emulator enough that it is difficult to tell the lag between pushing a control and the function activating. The frustrating part is that I reintroduced an artifact I thought I dealt with; probably due to no range checking.

Related Discussions

Related Forums