News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

HJWasm .SWITCH - .CASE - .DEFAULT - .ENDSWITCH

Started by habran, April 10, 2016, 08:26:42 PM

Previous topic - Next topic

qWord

not surprisingly that that such code blow up in your face: global variables (in a "recursive environment") and names like a,b,... casen, ncase ,...
8)

The lifecycle of pcases and plabesl in hll.c look suspicious (from the github repo)

MREAL macros - when you need floating point arithmetic while assembling!

habran

That is good find JJ :t
Now we have to find why is CurrSeg->e.seginfo->LinnumQueue having wrong data

qWord, I can assure you that problem is not there, I tried to use hll->casen and it has the same problem
If that would be a problem, 64 bit wouldn't work either
Cod-Father

habran

I am almost certain that problem comes from coff.c
read from line 1138
Cod-Father

qWord

A short session with clang's AddressSanitizer...:

  • HllExitDir@hll.c: local variable uint64_t n is passed as pointer to myatoi128, but the functions requires an array of two elements.
  • memory_operand@parser.c, line 1590 and 1591: index and base are used without checking for EMPTY.

Another problem, as already said, is pcases/plabels in hll.c: Beside that this solution can't work for nested control blocks (at least I can't see the change currently), these variables are tested for null-pointers but never set to zero after freeing.

I would strongly suggest to enable all warnings /Wall and then selectively disable warnings that (currently) makes no sense to fix. Doing so you can (i.a.) quickly find that the header guard for types.h is broken.

regards
MREAL macros - when you need floating point arithmetic while assembling!

habran

Hi qWord,
You were right in saying that global variables can't work for nested control blocks, so I have changed it to hll->pcases
and hll->plabels, and that works fine in x64,however, now x86 has got general failure with or without /Zi
have look for yourself
Cod-Father

HSE

Take with care...  :icon_eek:

but  Work!!  :t
Equations in Assembly: SmplMath

habran

Cod-Father

HSE

#97
See the test. The table has correct addresses now. Of course, all this things with "H".

Equations in Assembly: SmplMath

habran

I am not sure that I understood what you said :dazzled:
can you try to build that:


;--- Win32 "hello world" console application.
;--- assemble: HJWasm -coff Win32_1.ASM
;--- link:     JWlink format win pe file Win32_1.OBJ lib kernel32.lib
;--- or, linking with MS link:
;---           link Win32_1.obj kernel32.lib

    .486
    .MODEL FLAT, stdcall
    option casemap:none
    ;option DOTNAME
STD_OUTPUT_HANDLE equ -11

WriteConsoleA proto :dword, :dword, :dword, :dword, :dword
GetStdHandle  proto :dword
ExitProcess   proto :dword

    .CONST

string  db 13,10,"hello, world.",13,10

    .CODE

main proc c

local   dwWritten:dword
local   hConsole:dword
int 3

  mov eax,'ABCF'
.switch eax
  .case 'ABCD'
  .case 'BCDE'
  .case 'ABCC'
     mov  edx,'ABCG'
     .break
    .case 'ABCF'
     mov  edx,'ABCF'
    .break
  .case 'ABCI'
     mov edx,'ABCI'
    .break
  .case 'ABCJ'
     mov edx,'ABCJ'
    .break
  .default
     mov edx,0
     .break
.endswitch

   mov eax,252
.switch eax
  .case 2
     mov  edx,2 
     .break
    .case 280
     mov  edx,280 
    .break
  .case 252
     mov  edx,252 
    .break
  .case 274
      mov edx,274
    .break
  .case 277
     mov  edx,277
    .break
  .case 281
     mov  edx,281 
    .break
  .case 269
     mov  edx,269
    .break
  .case 282
     mov  edx,282
    .break
  .case 283
     mov  edx,283
    .break
  .case 286
     mov  edx,286
    .break
  .default
     mov edx,0
     .break
.endswitch

  mov eax,252
.switch eax
  .case 273
     mov  edx,273 
     .break
    .case 280
     mov  edx,280 
    .break
  .case 252
     mov  edx,252 
    .break
  .case 274
      mov edx,274
    .break
  .case 277
     mov  edx,277
    .break
  .case 281
     mov  edx,281 
    .break
  .case 269
     mov  edx,269
    .break
  .case 282
     mov  edx,282
    .break
  .case 283
     mov  edx,283
    .break
  .case 286
     mov  edx,286
    .break
  .default
     mov edx,0
     .break
.endswitch

    invoke  GetStdHandle, STD_OUTPUT_HANDLE
    mov     hConsole,eax

    invoke  WriteConsoleA, hConsole, addr string, sizeof string, addr dwWritten, 0

    xor     eax,eax
    ret
main endp

;--- entry

mainCRTStartup proc c

    invoke  main
    invoke  ExitProcess, eax

mainCRTStartup endp

    END mainCRTStartup

Cod-Father

nidud

#99
deleted

HSE

#100
habran,
because the collision I have T_DOT_CASEH, .caseh, etc

I'm using link.
Equations in Assembly: SmplMath

habran

>HSE, that looks good and works on my laptop, did you build with /Zi option?

>nidud, I agree with you to some point and I am planing to enhance capabilities to the .switch, I don't agree with you that volatile registers should be preserved ( eax, edx, ecx, r8, r9,r10, r11)

For now here are both release binaries:
the x64 works fine and can create line numbers with /Zi option, that means it can be debugged at source level
the x86 works fine but can not create line numbers, so don't use /Zi option but you can link with DEBUGER
and debug code at code level
Cod-Father

habran

Here is x64

Just to let you know, both version are build with Visual Studio Comunity 15
It suppose to work fine because I have built it with /MT option
Let me know if some problems, please.

If you are happy with this we can upload it to the teraspace.

I will take some more time to improve everything, and hopefully find where is code being overwritten with line numbers
Cod-Father

nidud

#103
deleted

habran

Thanks nidud, I was just going through expraval.c to find the better solution, I wasnot happy with this either.
The hardest thing for me was to set up the base and make it work. Now I am looking how to fine tune it.
You are always giving me a precious tips and I appreciate it very much :bgrin:
When I was working on .for-.endfor I did the same in the first place but than I found the way how to use already existing functions to do that instead.

I will see if I can make it work that way 8)

Cod-Father