Announcement

Collapse
No announcement yet.

Inline code snippet

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Inline code snippet

    I have posted this code snippet below because I thought someone may have a
    use for it. It loads a list that is seperated by a single ascii zero and
    terminated by a double ascii zero into a combo box. Changing the message
    CB_ADDSTRING to LB_ADDSTRING will make it load a list box. The algo uses
    the old string instructions because it uses an API call in the middle of
    the algo which is much slower than assembler instructions so chasing any
    sped increase is a waste of time.

    The formatting in the line starting with "entry$" will need to be changed
    to suit. The reason why there is no need to preserve registers either side
    of the SendMessage call is that the algo uses ESI/EDI that are preserved
    by convention in windows and the return value in EAX which is not used is
    overwritten with the following LODSB instruction.

    Regards,

    [email protected]

    Code:
          buffer$ = space$(256)
          spare$  = space$(8)
          GetLogicalDriveStrings len(buffer$),ByVal StrPtr(buffer$)
      
          src = StrPtr(buffer$)
          dst = StrPtr(spare$)
      
          ! mov esi, src    ; load source address
          ! mov edi, dst    ; load destination address
        lcStart:
          ! lodsb           ; load BYTE
          ! cmp al, 0       ; test for zero
          ! je lcNxt        ; jump to subloop if zero
          ! stosb           ; else write BYTE
          ! jmp lcStart     ; jump back to start of loop
        lcNxt:
          ! stosb           ; write terminator
          entry$ = "[-"+remove$(left$(spare$,instr(spare$,chr$(0))-1),":\")+"-]"
          SendMessage hCombo,%CB_ADDSTRING,0,ByVal StrPtr(entry$)
          ! lodsb           ; load next byte
          ! cmp al, 0       ; check if its a 2nd zero
          ! je lcQuit       ; if so, exit loop
          ! mov edi, dst    ; put destination address back in ESI
          ! stosb           ; write last BYTE
          ! jmp lcStart     ; jump back to start
        lcQuit:
      
          look$ = "[-"+left$(curdir$,1)+"-]"
          SendMessage hCombo,%CB_SETCURSEL, _
                      SendMessage(hCombo,%CB_FINDSTRING, _
                      -1,ByVal StrPtr(look$)),0

    ------------------
    hutch at movsd dot com
    The MASM Forum

    www.masm32.com
Working...
X