How to compare and move other size in assembly 8 bit and 16 bit -


code:

   ax=2013     al=ah+1     if (bx<al)     bx=al     bl=bh*3-ah     end if  

anyone can convert code assembly?

due question's title, assume part causing problems:

if (bx<al)     bx=al 

first, need clear whether have unsigned or signed values. then, can 0 or sign-extend 8 bit register available 16 bit one, , perform comparison , assignment using that. such unsigned:

    movzx cx, al ; 0 extend 16 bits     cmp bx, cx     jae skip     ; unsigned condition     mov bx, cx skip: 

or signed:

    movsx cx, al ; sign extend 16 bit     cmp bx, cx     jge skip     ; signed condition     mov bx, cx skip: 

if not allowed use register, can build comparison 8 bit halves manually. unsigned example:

    test bh, bh     jnz skip     ; if bh != 0 bx > al     cmp bl, al     jae skip     movzx bx, al skip: 

if movzx not available (it 386+ instruction) can emulate zeroing top 8 bits, such as:

    test bh, bh     jnz skip     ; if bh != 0 bx > al     cmp bl, al     jae skip     xor bh, bh     mov bl, al skip: 

for signed more complicated, left exercise :-)


Comments