You want to implement a if-else structure in your assembly code as in the following C-code
if (al == 0x41) { // we keep your example values // do something setASize(); } else { // do something else // not present in your code but there for the sake of completeness }
In assembly, you will write this the following way:
cmp al, h41 ; this is the comparison, which sets flags jne elseBranch ; if the zero flag is *not* set (al != h41) jump to elseBranch ; the jne instruction can be replaced with any other conditional ; jump to adjust to the test condition ifBranch: ; useless label for clarity call setASize ; this is the actual if-code (do-something) jmp endIf ; now jump to the end of the if to avoid the else-branch elseBranch: ; nothing in your code, but this is where you put ; your else instructions endIf: ; now is the code after your if-else block, which will be executed in any case
This is the one of the two classic ways to write a if-else block in assembly (the reasonning is the same only the instructions change). The other option is to put the else-branch code before the if-branch to have the more logical conditional jump (since in the first example we test equality but jump if not equal). With this second option, the assembly code would be
cmp al, h41 ; this is the comparison, which sets flags je ifBranch ; if the zero flag is *not* set (al != h41) jump to elseBranch ; the jne instruction can be replaced with any other conditional ; jump to adjust to the test condition elseBranch: ; useless label for clarity ; nothing in your code, but this is where you put ; your else instructions jmp endIf ; now jump to the end of the if to avoid the else-branch ifBranch: call setASize ; this is the actual if-code (do-something) endIf: ; now is the code after your if-else block, which will be executed in any case
In your case, since there is no else branch, the first option is prefered (only one jump required since you do not need to jump to the elseBranch labels (and do not need the second endIf jump).
For you code, the final answer would be:
cmp al,41h jne endIf call setAsize endIf: ; more code here setASize: mov al,4d ret
alare limited unless you're happy with a table of 256 addresses, you could make a call table where all the values point to a subroutine that does nothing, and the entry at 41h points tosetAsize. In this case, a simple compare and jump would be more straightforward.