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 January 29th, 2005, 09:23 PM
    joblaise joblaise is offline
    Junior Member
     
    Join Date: Jan 2005
    Posts: 2
    joblaise is an unknown quantity at this point (<10)
    Will this code set and clear zero and sign flags

    I'm a beginning and am having problems with this code. I think my problem is with my data statement. Please provide help. Here's the code:

    .data
    .386
    .model flat, stdcall
    option casemap :none ; case sensitive
    .code
    main PROC

    mov cl,1 ; CL=1
    sub cl,1 ; CL=0, SF=0, ZF=1
    call DumpRegs

    sub cl,1 ; CL=-1, SF=1, ZF=0
    call DumpRegs

    add ch,1 ; CH=0, SF=0, ZF=1
    call DumpRegs

    add ch,1 ; CH=1, SF=0, ZF=0
    call DumpRegs

    exit
    main ENDP
    END main
    Reply With Quote
      #2    
    Old January 30th, 2005, 09:10 AM
    NoHero's Avatar
    NoHero NoHero is offline
    Moderator
     
    Join Date: Mar 2004
    Location: (Upper-) Austria
    Posts: 2,899
    NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)NoHero has much to be proud of (1500+)
    Re: Will this code set and clear zero and sign flags

    To manipulate the CPU flags you can use the pushf and popf functions. The push and pop the flag register onto the stack. With that you can retrieve the flags modify them and set them back.

    Code:
    pushf
    pop ax
    ; Now modify them, they are in ax
    push ax
    popf
    / 10 posts to go
    __________________
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

    Last edited by NoHero; January 30th, 2005 at 09:18 AM.
    Reply With Quote
      #3    
    Old January 30th, 2005, 12:46 PM
    joblaise joblaise is offline
    Junior Member
     
    Join Date: Jan 2005
    Posts: 2
    joblaise is an unknown quantity at this point (<10)
    Re: Will this code set and clear zero and sign flags

    Thanks for the response. I see that you used an alternative method, which is good to know. However, I was wondering if the code I wrote could be used, and if so, what am I doing wrong to make it execute properly?

    Thanks in advance for your help.
    Reply With Quote
      #4    
    Old January 30th, 2005, 07:10 PM
    OReubens OReubens is offline
    Senior Member
     
    Join Date: Apr 2000
    Location: Belgium (Europe)
    Posts: 2,038
    OReubens  is a jewel in the rough (300+)OReubens  is a jewel in the rough (300+)OReubens  is a jewel in the rough (300+)OReubens  is a jewel in the rough (300+)
    Re: Will this code set and clear zero and sign flags

    Quote:
    Originally Posted by joblaise
    Thanks for the response. I see that you used an alternative method, which is good to know. However, I was wondering if the code I wrote could be used, and if so, what am I doing wrong to make it execute properly?

    Thanks in advance for your help.
    Well, you never set CH to anything, so the call
    Code:
    add ch,1 ; CH=0, SF=0, ZF=1
    call DumpRegs
    Will not do as you think (not what's in the comment).

    I'm guessing you wanted to use CL instead of CH.


    You can also manipulate set flags via
    - SAHF (sotre AH into flags). This will only modify the lower 8 bits of the flags. 'extended' 32bit flags won't be changed.

    Direction, interupt enable, Carry flags can be set/cleared directly via CLD/STD, CLI/STI, CLC/STC
    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:22 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