Click here to Skip to main content
15,892,059 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: MASM 9.0 bug. Pin
OriginalGriff15-Jan-15 22:55
mveOriginalGriff15-Jan-15 22:55 
QuestionRe: MASM 9.0 bug. Pin
ZurdoDev15-Jan-15 8:49
professionalZurdoDev15-Jan-15 8:49 
AnswerRe: MASM 9.0 bug. Pin
Kenneth Haugland15-Jan-15 8:59
mvaKenneth Haugland15-Jan-15 8:59 
GeneralRe: MASM 9.0 bug. Pin
harold aptroot15-Jan-15 9:10
harold aptroot15-Jan-15 9:10 
AnswerRe: MASM 9.0 bug. Pin
Nelek15-Jan-15 13:40
protectorNelek15-Jan-15 13:40 
GeneralRe: MASM 9.0 bug. Pin
Richard MacCutchan15-Jan-15 9:00
mveRichard MacCutchan15-Jan-15 9:00 
GeneralRe: MASM 9.0 bug. Pin
newton.saber15-Jan-15 9:14
newton.saber15-Jan-15 9:14 
GeneralRe: MASM 9.0 bug. Pin
Member 419459315-Jan-15 9:27
Member 419459315-Jan-15 9:27 
Thank you for the invitation.

Just a warning to all.

I had a function which had always been working. I modified it to align a short loop (added ALIGN OWORD). The function fails to function correctly (did not cause an error - just bad results which caused other errors - quite difficult to determine just what was happening). The data was 8 DWORDS which were all 0 except most significant which was 40000000h, and I was subtracting a single DWORD with a value of 1. I expected to get 7 DWORDS of FFFFFFFFh and the most significant DWORD with 3FFFFFFFh:

This is the source code:

;*******************************************************************************
;
;   SUB a LONG_NUMB value from another. This is a routine called to subtract a
;   long number from another after all scaling and validations have been done.
;
;       esi has the source OFFSET of the data.
;       edi has the already scaled OFFSET of the destination data.
;       ecx has the DWORD count to subtract.
;
;   Returns nothing with edi pointing to the last word modified. Note that this
;   may not be the highest DWORD in the destination if a short source is
;   subtracted from a long destination and there are no borrows past the last
;   DWORD in the destination or source. This is primarily a check for a size
;   extension due to a final borrow.
;
;*******************************************************************************

ALIGN   OWORD

SUBIt   PROC PRIVATE USES eax ebx esi

    pushfd
    clc
;
;   subtract all the value DWORDS.
;
ALIGN      OWORD

DoAll:
    mov    ebx,[esi]
    lea    esi,[esi + (SIZEOF DWORD)]
    sbb    [edi],ebx
    lea    edi,[edi + (SIZEOF DWORD)]
    dec    ecx
    jnz    DoAll
    jnc    Exit
    mov    eax,0
;
;   Propogate the borrow.
;
ALIGN      OWORD

Again:
    sbb    [edi],eax
    lea    edi,[edi + (SIZEOF DWORD)]
    jc     Again
;
;   Exit SUBIt, adjust the destination pointer to the last modified DWORD.
;
Exit:
    sub    edi,(SIZEOF DWORD)
    popfd
    test   dTestZero,0
    ret
SUBIt   ENDP


This is the generated code from MASM 9.0 (Visual Studio "Disassembly" tab):

ALIGN   OWORD

SUBIt   PROC PRIVATE USES eax ebx esi
00404FC0  push        eax  
00404FC1  push        ebx  
00404FC2  push        esi  

    pushfd
00404FC3  pushfd           
    clc
00404FC4  clc              
00404FC5  lea         esp,[esp] 
00404FCC  lea         esp,[esp] 
;
;   subtract all the value DWORDS.
;
ALIGN      OWORD

DoAll:
    mov    ebx,[esi]
00404FD0  mov         ebx,dword ptr [esi] 
    lea    esi,[esi + (SIZEOF DWORD)]
00404FD2  lea         esi,[esi+4] 
    sbb    [edi],ebx
00404FD5  sbb         dword ptr [edi],ebx 
    lea    edi,[edi + (SIZEOF DWORD)]
00404FD7  lea         edi,[edi+4] 
    dec    ecx
00404FDA  dec         ecx  
    jnz    DoAll
00404FDB  jne         DoAll (404FD0h) 
    jnc    Exit
00404FDD  jae         Exit (404FF7h) 
    mov    eax,0
00404FDF  mov         eax,0 
00404FE4  lea         esp,[esp] ************************** alignment inserted instructions 
00404FEB  add         eax,0 ****************************** think this might reset the carry Flag?
;
;   Propogate the borrow.
;
ALIGN      OWORD ***************************************** just added this to help speed up the code

Again:
    sbb    [edi],eax
00404FF0  sbb         dword ptr [edi],eax **************** and cause the SBB here to fail?
    lea    edi,[edi + (SIZEOF DWORD)]
00404FF2  lea         edi,[edi+4] 
    jc     Again
00404FF5  jb          Again (404FF0h) 
;
;   Exit SUBIt, adjust the destination pointer to the last modified DWORD.
;
Exit:
    sub    edi,(SIZEOF DWORD)
00404FF7  sub         edi,4 
    popfd
00404FFA  popfd            
    test   dTestZero,0
00404FFB  test        dword ptr [dTestZero (40C6BCh)],0 
    ret
00405005  pop         esi  
00405006  pop         ebx  
00405007  pop         eax  
00405008  ret              
00405009  lea         esp,[esp] 
SUBIt   ENDP


>Beware!

Dave.
GeneralRe: MASM 9.0 bug. Pin
harold aptroot15-Jan-15 9:36
harold aptroot15-Jan-15 9:36 
GeneralRe: MASM 9.0 bug. Pin
Jeremy Falcon15-Jan-15 12:15
professionalJeremy Falcon15-Jan-15 12:15 
GeneralRe: MASM 9.0 bug. Pin
Member 419459316-Jan-15 4:32
Member 419459316-Jan-15 4:32 
GeneralRe: MASM 9.0 bug. Pin
harold aptroot16-Jan-15 5:01
harold aptroot16-Jan-15 5:01 
GeneralRe: MASM 9.0 bug. Pin
Member 419459316-Jan-15 6:33
Member 419459316-Jan-15 6:33 
GeneralRe: MASM 9.0 bug. Pin
harold aptroot16-Jan-15 7:21
harold aptroot16-Jan-15 7:21 
GeneralRe: MASM 9.0 bug. Pin
Member 419459316-Jan-15 12:17
Member 419459316-Jan-15 12:17 
GeneralRe: MASM 9.0 bug. Pin
S Douglas15-Jan-15 18:55
professionalS Douglas15-Jan-15 18:55 
GeneralRe: MASM 9.0 bug. Pin
DJ van Wyk16-Jan-15 0:32
professionalDJ van Wyk16-Jan-15 0:32 
GeneralRe: MASM 9.0 bug. Pin
Member 419459316-Jan-15 4:25
Member 419459316-Jan-15 4:25 
General"Cloud computing" make me cringe. Pin
Leng Vang15-Jan-15 7:19
Leng Vang15-Jan-15 7:19 
GeneralRe: "Cloud computing" make me cringe. Pin
Marc Clifton15-Jan-15 7:32
mvaMarc Clifton15-Jan-15 7:32 
GeneralRe: "Cloud computing" make me cringe. Pin
OriginalGriff15-Jan-15 8:02
mveOriginalGriff15-Jan-15 8:02 
GeneralRe: "Cloud computing" make me cringe. Pin
Jörgen Andersson15-Jan-15 8:38
professionalJörgen Andersson15-Jan-15 8:38 
GeneralRe: "Cloud computing" make me cringe. Pin
OriginalGriff15-Jan-15 8:48
mveOriginalGriff15-Jan-15 8:48 
GeneralRe: "Cloud computing" make me cringe. Pin
Mycroft Holmes15-Jan-15 13:53
professionalMycroft Holmes15-Jan-15 13:53 
GeneralRe: "Cloud computing" make me cringe. Pin
Mark_Wallace15-Jan-15 15:16
Mark_Wallace15-Jan-15 15:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.