Doubt in Prime.asm

Hello Everybody, I am having some doubts regarding the attatched code from the book "PC Assembly", based on Pentium III architecture.

I am Beginner to assembly,

I am unable to understand, the line 49 of the code:
49 je end_if ; if !(guess % factor != 0)
Actually the code is working fine, but I am not understanding that, how [b]je[/b] is being treadted here.
According to me, if a jump from line 44 to line 49 will occur, then it is okay as in line 43 we are doing a comparison(cmp) of remainder with 0.
But if we jump from line 37 or 39, then how will je check the flags.

Another Question, I am bit confused with carry flag and Overflow flag.

Please try to solve my doubt. I want to complete this book as soon as possible.


  • This post has been deleted.
  • The instruction je(jump if equal) is a conditional jump equivalent with jz (jump if zero) and jumps to a specific label (in this case end_if) only if when the instruction is executed ZF(zero flag) is set. If that jump is avoided by others then maybe it's a nested condition, a C language equivalent would be something like this:
    if(condition 1)
    if(condition 2)
    //some code
    But I can't say for sure, only if you put the entire source code.

    As for the CF and OF, they are used to notify you that something has happened during the last instruction . Here are some examples:

    When you add two bytes CF is set if there is a carry bit ( the result won't fit in 8 bit representation) and OF is set when the sign bit of the operands have a value and the result's sign bit has the oposite value ( usefull when dealing with signed numbers)

    Overflow at division is encountered when you divide a large number to a small one and the quotient won't fit in the LOW register.Try dividing the word 1000 at 2 and you will get 'Division by zero' (interrupt 0) because 500 won't fit into the byte AL.

    Overflow at multiplication is not an actual "overflow" because the result will alway fit in its representation, but OF will notify you if the result can be stored in the LOW register(2*4 will fit in AL but 2*400 won't).

    When you perform some shift operations the first/last bit is sent to CF
    and so on....

    For more details you should read the specifications of each instruction to see how these are modifying those flags.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion