Search code examples
assemblypseudocodeflags

assembly code confusion? stock at these two problems


  1. the value of status flag bits (0 or 1) after execution of the add instruction. explain

     mov bx, 8000h
     add bx, 8000h
     c  this should be 0 because carry flag is not changed?
     0  this should be 1 because the sum is not zero?
     s  this should be not signed?
     z  ?
    
  2. convert the pseudo-code into assembly, assumes value are signed integers and short circuited evaluation is used. the code should be compact.

    if(eax<ecx) AND (ebx != edx) {
     mov edi, esi;
     add ebx, eax;
    }
    

I'm really lost at this anyone want give some guidance?


Solution

  • Ah, a homework. Jack Daniels in my veins says I should help you :)

    1 0x8000 + 0x8000 = 0x10000. Result is 17 bits, thus but your register is only 16 bits. So, only 0x0000 will be stored in BX.
    With this you will get the following flags set:
    - OF is set (sum is greater than register can hold);
    - CF is set (highest bit of the result is 1)
    - PF is set (number is even)
    - ZF is set (BX = 0)
    - SF is not set (not a signed number)

    2 (fasm syntax)

    cmp eax, ecx
    jge short @f
    cmp ebx, edx
    jz short @f
    mov esi, edi
    add eax, ebx
    @@: