CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Installing SQL Server 2008
  • Writing UDFs for Firebird Embedded SQL Server
  • [Updated] Shutdown Manager
  • Building Windows Azure Cloud Service Applications with Azure Storage and the Azure SDK

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Other Programming > Assembly
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Assembly Questions and Answers for Assembly here!

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old November 11th, 2004, 07:22 AM
    _Dave_ _Dave_ is offline
    Junior Member
     
    Join Date: Nov 2004
    Posts: 10
    _Dave_ is an unknown quantity at this point (<10)
    Carry Flag

    Hello CodeGurus.

    I am reading "Assembly Language for Intel-Based Computers" by Kip R. Irvine. Section 4.2.6.2 is about the Carry Flag (CF). It says if we subtract an integer from a smaller integer, the CF will be set. This is true when I run, for example...
    Code:
    .data
    val1 BYTE 1
    val2 BYTE 2
    
    .code
    mov al, val1
    sub al, val2	; CF = 1 SF = 1
    But when I do the arithmetic on paper...
    Code:
    Carry
             0000 0001   1
             1111 1110  -2
    
             1111 1111		which is -1 in 2's complement form.
    Where is the carry out??? It says earlier in the book that the CF is set when the result of an unsigned arithmetic operation is too large to fit into the destination operand. But -1 fits into AL.

    Thanks,
    Dave
    Reply With Quote
      #2    
    Old November 27th, 2004, 03:43 AM
    kahlinor kahlinor is offline
    Member
     
    Join Date: Nov 2004
    Posts: 34
    kahlinor is an unknown quantity at this point (<10)
    Re: Carry Flag

    Hi, Dave.

    Your doing a 1+ ( NEG 2 ) operation on 'paper' which will only set the sign flag in computer flags terms, even though you get the exact same result as SUB 1, 2


    I have written a little utility which gives you a visual look at what happens to registers and flags during logical and arithmatic operations.

    If you're interested, take a look at my cCalc program, attached.

    -Sevag K.
    Attached Files
    File Type: zip cCalc.zip (8.9 KB, 134 views)
    Reply With Quote
      #3    
    Old November 27th, 2004, 07:43 PM
    kahlinor kahlinor is offline
    Member
     
    Join Date: Nov 2004
    Posts: 34
    kahlinor is an unknown quantity at this point (<10)
    Re: Carry Flag

    Let me clarify the previous post a little bit.

    Rules for Binary Subtraction:

    0 - 0 = 0
    1 - 0 = 1
    1 - 1 = 0
    0 - 1 = 1 w/borrow

    0000 0001
    0000 0010
    --------------
    1111 1111
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Other Programming > Assembly


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 08:47 PM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
    Copyright WebMediaBrands Inc. 2002-2009