Author Topic: HJWASM 2.17 bugs  (Read 14923 times)

habran

  • Member
  • *****
  • Posts: 1215
    • uasm
Re: HJWASM 2.17 bugs
« Reply #30 on: January 01, 2017, 09:39:29 PM »
I have checked also what C does and it comes out the same as masm and your fix, so I have implemented your idea and now hjwasm does the same. Here is the c source:
Code: [Select]
static ret_code GetAndExpression(struct hll_item *hll, int *i, struct asm_tok tokenarray[], int ilabel, bool is_true, char *buffer, struct hll_opnd *hllop)
/***********************************************************************************************************************************************************/
{
  char *ptr = buffer;
  uint_32 truelabel = 0;
  char buff[16];
  int nlabel;
  int olabel;

  DebugMsg1(("%u GetAndExpression(>%.32s< buf=>%s<) enter\n", evallvl, tokenarray[*i].tokpos, buffer));

  if (ERROR == GetSimpleExpression(hll, i, tokenarray, ilabel, is_true, ptr, hllop))
    return(ERROR);
  while (COP_AND == GetCOp(&tokenarray[*i])) {

    (*i)++;
    DebugMsg1(("%u GetAndExpression: &&-operator found, is_true=%u, lastjmp=%s\n", evallvl, is_true, hllop->lastjmp ? hllop->lastjmp : "NULL"));

    if (is_true) {
      /* todo: please describe what's done here and why! */
      if (hllop->lastjmp) {
        char *p = hllop->lastjmp;
        InvertJump(p);          /* step 1 */
        if (truelabel == 0)     /* step 2 */
          truelabel = GetHllLabel();

        if (*p ) {/* v2.11: there might be a 0 at lastjmp */
          p += 4;               /* skip 'jcc ' or 'jmp ' */
          GetLabelStr(truelabel, p);
          strcat(p, EOLSTR);
        }
        /* HJWasm 2.18  fixed WHILE with &&  */
        if (hllop->lasttruelabel)
          ReplaceLabel(buffer,hllop->lasttruelabel, truelabel);
        if (hll->cmd == HLL_WHILE){     // this is nidud's idea
          nlabel = GetHllLabel();
          olabel = GetLabel(hll, ilabel);
          GetLabelStr(olabel, buff);
          strcat(ptr, buff);
          strcat(ptr, LABELQUAL EOLSTR);
          DebugMsg1(("%u GetAndExpression: label added >%s<\n", evallvl, ptr));
          ReplaceLabel(buffer, olabel, nlabel);
          }
        else{
          DebugMsg1(("%u GetAndExpression: jmp inverted >%s<\n", evallvl, hllop->lastjmp));
          ReplaceLabel(buffer, GetLabel(hll, ilabel), truelabel);
          }
        hllop->lastjmp = NULL;
      }
    }
    ptr += strlen(ptr);
    hllop->lasttruelabel = 0; /* v2.08 */
    if (ERROR == GetSimpleExpression(hll, i, tokenarray, ilabel, is_true, ptr, hllop))
      return(ERROR);
  };

  if (truelabel > 0) {
    ptr += strlen(ptr);
    GetLabelStr(truelabel, ptr);
    strcat(ptr, LABELQUAL EOLSTR);
    DebugMsg1(("%u GetAndExpression: label added >%s<\n", evallvl, ptr));
    hllop->lastjmp = NULL;
  }
  return(NOT_ERROR);
}
Cod-Father

nidud

  • Member
  • *****
  • Posts: 1824
    • https://github.com/nidud/asmc
Re: HJWASM 2.17 bugs
« Reply #31 on: January 02, 2017, 01:26:25 AM »
Code: [Select]
        if (hll->cmd == HLL_WHILE){     // this is nidud's idea
          nlabel = GetHllLabel();
          olabel = GetLabel(hll, ilabel);
          GetLabelStr(olabel, buff);
          strcat(ptr, buff);
          strcat(ptr, LABELQUAL EOLSTR);
          DebugMsg1(("%u GetAndExpression: label added >%s<\n", evallvl, ptr));
          ReplaceLabel(buffer, olabel, nlabel);
          }
        else{
          DebugMsg1(("%u GetAndExpression: jmp inverted >%s<\n", evallvl, hllop->lastjmp));
          ReplaceLabel(buffer, GetLabel(hll, ilabel), truelabel);
          }

I also parse general expressions in other HLL statements and this also include function calls, so the if (hll->cmd == HLL_WHILE) thing is not really needed in HJWASM. It was inserted to exclude .CASE <expressions> but that seems to need the same handling as .WHILE in this case.

This is the current version:
Code: [Select]
GetAndExpression PROC USES esi edi ebx,
hll: PTR hll_item,
i: PTR SINT,
tokenarray: PTR asm_tok,
ilabel: UINT,
is_true: UINT,
buffer: LPSTR,
hllop: PTR hll_opnd

local truelabel: SINT,
nlabel: SINT,
olabel: SINT,
buff[16]: SBYTE

mov edi,hllop
mov esi,buffer
mov truelabel,0

.while 1

GetSimpleExpression( hll, i, tokenarray, ilabel, is_true, esi, edi )
cmp eax,ERROR
je toend
mov ebx,i
mov eax,[ebx]
shl eax,4
add eax,tokenarray
.break .if GetCOp( eax ) != COP_AND
inc DWORD PTR [ebx]
mov ebx,[edi].hll_opnd.lastjmp
.if ebx && is_true

InvertJump( ebx )

.if truelabel == 0

mov truelabel,GetHllLabel()
.endif
;
; v2.11: there might be a 0 at lastjmp
;
.if BYTE PTR [ebx]

strcat( GetLabelStr( truelabel, addr [ebx+4] ), addr EOLSTR )
.endif
;
; v2.22 .while (eax || edx) && ecx -- failed
; .while !(eax || edx) && ecx -- failed
;
mov ebx,esi
.if [edi].hll_opnd.lasttruelabel

ReplaceLabel( ebx, [edi].hll_opnd.lasttruelabel, truelabel )
.endif
mov nlabel,GetHllLabel()
mov olabel,GetLabel( hll, ilabel )
strlen( ebx )
add ebx,eax
sprintf( ebx, "%s%s%s", GetLabelStr( olabel, addr buff ), addr LABELQUAL, addr EOLSTR )
ReplaceLabel( buffer, olabel, nlabel )
mov [edi].hll_opnd.lastjmp,0
.endif

strlen( esi )
add esi,eax
mov [edi].hll_opnd.lasttruelabel,0
.endw

.if truelabel

strlen( esi )
add esi,eax
strcat( strcat( GetLabelStr( truelabel, esi ), addr LABELQUAL ), addr EOLSTR )
mov [edi].hll_opnd.lastjmp,0
.endif
mov eax,NOT_ERROR
toend:
ret
GetAndExpression ENDP

LiaoMi

  • Member
  • ****
  • Posts: 625
Re: HJWASM 2.17 bugs
« Reply #32 on: January 02, 2017, 01:48:16 AM »
Bug #3, I have to check yet and Bug #4 is half true, if you use original HJWasm from Teraspace, it will show source code and line nmbers because it is built with msvc2005ddk. Visual Studio is producing different debug info which HJWasm doesn't support.
So, to have fast and small exe with a proper debug info you need to build it with the msvc2005ddk

Hello everybody!

Where can I download msvc 2005 ddk? On the Internet is very hard to find ..

Happy New Year! Thanks!

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 6861
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: HJWASM 2.17 bugs
« Reply #33 on: January 02, 2017, 02:26:07 AM »
See if this will give you the correct version.

https://www.microsoft.com/en-au/download/details.aspx?id=11800
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

habran

  • Member
  • *****
  • Posts: 1215
    • uasm
Re: HJWASM 2.17 bugs
« Reply #34 on: January 02, 2017, 06:18:03 AM »
LiaoMi, I think that msvc2003R2.zip is what you need
and here is the .cmd file:
Code: [Select]
@SET Path=C:\code1\msvc2003R2\bin\amd64
@SET INCLUDE=C:\code1\msvc2003R2\include\crt;
@SET LIB=C:\code1\msvc2003R2\lib\amd64
cl -c -Zl -GS- -O2 -Ox -I..\HJWasm-master\H ..\HJWasm-master\*.c -D_CRT_SECURE_NO_DEPRECATE -DDEBUG_OUT -DWIN64 -DAVXSUPP
cl main.obj apiemu.obj assemble.obj assume.obj atofloat.obj backptch.obj bin.obj branch.obj cmdline.obj codegen.obj coff.obj condasm.obj context.obj cpumodel.obj data.obj dbgcv.obj directiv.obj elf.obj end.obj equate.obj errmsg.obj expans.obj expreval.obj extern.obj fastpass.obj fixup.obj fpfixup.obj hll.obj input.obj invoke.obj label.obj linnum.obj listing.obj loop.obj lqueue.obj macro.obj mangle.obj memalloc.obj msgtext.obj omf.obj omffixup.obj omfint.obj option.obj parser.obj posndir.obj preproc.obj proc.obj queue.obj reswords.obj safeseh.obj segment.obj simsegm.obj string.obj symbols.obj tbyte.obj tokenize.obj types.obj libc.lib bufferoverflowu.lib -o hjwa64v200R2clib.exe
@DEL *.obj
pause
Cod-Father

habran

  • Member
  • *****
  • Posts: 1215
    • uasm
Re: HJWASM 2.17 bugs
« Reply #35 on: January 02, 2017, 07:58:09 AM »
I think that TWell can give you all info you need about building with DDK, you can PM him 8)
Cod-Father

TWell

  • Member
  • ****
  • Posts: 748
Re: HJWASM 2.17 bugs
« Reply #36 on: January 02, 2017, 08:03:27 AM »
For x86 old MS Visual C++ Toolkit 2003 should work, but it is hard to find :(
Also x86 compiler and libc.lib are in 1830_usa_ddk.iso

EDIT: Server 2003 SP1 Platform SDK ISO
« Last Edit: January 08, 2017, 03:40:17 AM by TWell »

habran

  • Member
  • *****
  • Posts: 1215
    • uasm
Re: HJWASM 2.17 bugs
« Reply #37 on: January 02, 2017, 08:39:33 AM »
Thanks TWell, excellent stuff :t
Cod-Father

Vortex

  • Member
  • *****
  • Posts: 2059
Re: HJWASM 2.17 bugs
« Reply #38 on: January 03, 2017, 08:10:51 AM »
For x86 old MS Visual C++ Toolkit 2003 should work, but it is hard to find :(

You can check this link :

http://www.unfiles.info/vctoolkitsetup.exe/m-download-23770.html

ragdog

  • Member
  • ****
  • Posts: 610
Re: HJWASM 2.17 bugs
« Reply #39 on: January 07, 2017, 01:12:35 AM »
Hello

I testing hJwasm as new Assembler why give hJwasm to cryptic output

Total compile time 734 ms
×ܹ²±àÒëʱ¼ä 734 ºÁÃë  <<<<<<<<

And give any macro or function to auto translate registers?

example

if _WIN64 EQU 1 ; registers are auto translated eax to rax etc...

Code example my way is really dirty to use a one project  code to build a x86 app or X64
Or has any a better solution or macro?

Code: [Select]
IFDEF _WIN64 
    _eax TEXTEQU <rax>
    _ebx TEXTEQU <rbx>
    _ecx TEXTEQU <rcx>
    _edx TEXTEQU <rdx>
    _esi TEXTEQU <rsi>
    _edi TEXTEQU <rdi>
    _ebp TEXTEQU <rbp>
    _esp TEXTEQU <rsp>
 ELSE
    _eax TEXTEQU <eax>
    _ebx TEXTEQU <ebx>
    _ecx TEXTEQU <ecx>
    _edx TEXTEQU <edx>
    _esi TEXTEQU <esi>
    _edi TEXTEQU <edi>
    _ebp TEXTEQU <ebp>
    _esp TEXTEQU <esp>
 ENDIF

mov _eax,1

Greets,
« Last Edit: January 07, 2017, 06:23:46 AM by ragdog »

habran

  • Member
  • *****
  • Posts: 1215
    • uasm
Re: HJWASM 2.17 bugs
« Reply #40 on: January 07, 2017, 08:26:00 AM »
Hi ragdog,
It sims to me that you are using some other language then English for your text editor :biggrin:
It is pretty complex job to write source that can be used for both 32 and 64 bit.
You can ask rrr314159 about the best way how to do that because he has done some conversion few years ago.
Cod-Father

habran

  • Member
  • *****
  • Posts: 1215
    • uasm
Re: HJWASM 2.17 bugs
« Reply #41 on: January 07, 2017, 08:30:24 AM »
Hi Vortex,
I have downloaded and installed Toolkit 2003 from your link, however, it is only 32 bit.

Here is Russian link for platformSDK2003SP1
« Last Edit: January 07, 2017, 10:06:32 AM by habran »
Cod-Father

ragdog

  • Member
  • ****
  • Posts: 610
Re: HJWASM 2.17 bugs
« Reply #42 on: January 07, 2017, 09:35:27 PM »
Quote
It sims to me that you are using some other language then English for your text editor

I use Radasm2 as Texteditor and use default language ( English)

Greets,

habran

  • Member
  • *****
  • Posts: 1215
    • uasm
Re: HJWASM 2.17 bugs
« Reply #43 on: January 07, 2017, 11:50:15 PM »
I don't know how to setup Radasm2 for HJWasm, I am using Visual Studio Community 2013 to build my programs.
You can PM Johnsa, to give you some tips how to setup Radasm2 for HJWasm.
Cod-Father

ragdog

  • Member
  • ****
  • Posts: 610
Re: HJWASM 2.17 bugs
« Reply #44 on: January 08, 2017, 01:49:35 AM »
Thank you