Beginner ASM question: jump instructions

This is a discussion on Beginner ASM question: jump instructions within the Tech Board forums, part of the Community Boards category; Code: FILE_OK: mov dx,OFFSET FNAME mov ax,3D02H int 21H jc FOK_NZEND ;error opening file ...... mov ax,WORD PTR [FSIZE] ; ...

  1. #1
    Android
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    362

    Beginner ASM question: jump instructions

    Code:
    FILE_OK:
           mov     dx,OFFSET FNAME
           mov     ax,3D02H            
           int     21H
           jc      FOK_NZEND  ;error opening file
           ......
           mov     ax,WORD PTR [FSIZE] ;
           add     ax,OFFSET ENDPROG - OFFSET PROG   ;
           jc      FOK_NZEND           ;c set if ax overflows (size > 64k)
           cmp     BYTE PTR [START_IMAGE],0E9H   ;
           jnz     FOK_ZEND            ;exit with z
           cmp     WORD PTR [START_IMAGE+3],4956H
           jnz     FOK_ZEND            ;return with Z set
    FOK_NZEND:
           mov     al,1                ;
           or      al,al               ;return with z reset
           ret
    FOK_ZEND:
           xor     al,al               ; return with z set
           ret
    Hi im unclear about the working of jump instructions above. What's the meaning of "c set if ax overflows" and "return with Z set"? whats the relationship with cmp and jnz here? how jc and jnz decide whether to jump to another function.

    Dont know if my question is clear. anyway, thanks for any input.
    Some useless programs i've wrote : slprogrammersheaven
    Youtube: http://www.youtube.com/user/geekyzine
    My amature IT Blog: http://everything-geeky.blogspot.com/
    My Flash games: http://flashweed.blogspot.com/

    (and, sorry for my amature english)

  2. #2
    Chinese pâté foxman's Avatar
    Join Date
    Jul 2007
    Location
    Canada
    Posts
    404
    What's the meaning of "c set if AX overflows"
    This comment means "The carry flag is set if ax overflows". "jc" means "jump if carry (is set)".

    ...and "return with Z set"
    On this one, I'm not exactly sure, but it looks like it has something to do with the "zero flag". In fact, it does look like Z means "zero flag" here

    whats the relationship with cmp and jnz here?
    Well, the cmp instruction sets the different flags accordingly to the result of the comparaison. The JNZ check if the zero flag is set and jump to the location if it is. JNZ is for "jump not zero" and "jc" is for "jump carry".

    I would suggest you to go to this site
    http://developer.intel.com/products/...uals/index.htm
    and download the Volume 1, Volume 2A and 2B. You'll see, they are handy if you are doing x86 (or x86-64) assembly.
    I hate real numbers.

  3. #3
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,069
    Here is the best manual that I know for x86 assembly if you have any questions about the op codes or standard syntax. Specifically in this case you're going to want to look at this section.
    Sent from my iPad®

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Classes Question
    By kbro3 in forum C++ Programming
    Replies: 9
    Last Post: 08-14-2008, 07:43 AM
  2. Same old beginner question...
    By Sharmz in forum C Programming
    Replies: 15
    Last Post: 08-04-2008, 11:48 AM
  3. Beginner: Linked List question
    By WeatherMan in forum C++ Programming
    Replies: 2
    Last Post: 04-03-2008, 07:16 AM
  4. Quick IF statement question (beginner)
    By jim.rattlehead in forum C Programming
    Replies: 23
    Last Post: 11-29-2007, 05:51 AM
  5. A very beginner question!
    By sifeet in forum C Programming
    Replies: 8
    Last Post: 11-06-2007, 06:13 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21