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

HSE

Hab1.asm (only one switch)

No evident problem with /Zi or /Zd at object compilation.

No problem with usual linking.

Problem linking with /Debug :hab1.obj : error : Internal error during Pass2

  ExceptionCode            = C0000005
  ExceptionFlags           = 00000000
  ExceptionAddress         = 65B01DA0
  NumberParameters         = 00000002
  ExceptionInformation[ 0] = 00000000
  ExceptionInformation[ 1] = 362935A9

CONTEXT:
  Eax    = 362935A1  Esp    = 0012F054
  Ebx    = 00000204  Ebp    = 0012F0B0
  Ecx    = 00000E00  Esi    = 0012F070
  Edx    = 008BEFE8  Edi    = 00000002
  Eip    = 65B01DA0  EFlags = 00010202
  SegCs  = 0000001B  SegDs  = 00000023
  SegSs  = 00000023  SegEs  = 00000023
  SegFs  = 0000003B  SegGs  = 00000000
  Dr0    = 0012F054  Dr3    = 00000204
  Dr1    = 0012F0B0  Dr6    = 00000E00
  Dr2    = 00000000  Dr7    = 00000000


But here...  Win32_1.asm:win32_1.asm(88) : Error A2168: General Failure

It's the line that follow the second .endswitch. Testing only one switch I never see this problem.
Equations in Assembly: SmplMath

habran

Cod-Father

habran

Hi nidud,
I have succeeded to implement EvalOperand() and now we can handle almost everything.
The only thing that is missing is "string", that needs a special handling


Quotecase T_DOT_CASE:
    if (hll->cmd != HLL_SWITCH) {
      DebugMsg(("HllExitDir stack error\n"));
      return(EmitError(DIRECTIVE_MUST_BE_IN_CONTROL_BLOCK));
    }
    hll->labels[LTEST] = GetHllLabel();
    AddLineQueueX("%s" LABELQUAL, GetLabelStr(hll->labels[LTEST], buff));
    i++;
    if (tokenarray.token != T_FINAL) {
      DebugMsg1(("HllExitDir(%s): calling EvalOperand, i=%u\n", tokenarray.string_ptr, i));
      if (EvalOperand(&i, tokenarray, Token_Count, &opndx, 0) == ERROR) {
        DebugMsg(("HllExitDir(%s): EvalOperand() failed\n", tokenarray.string_ptr));
        return(ERROR);
      }
      i++;
      switch (opndx.kind) {
      case EXPR_CONST:
        tokenarray.token = T_FINAL;
        break;
      case EXPR_FLOAT:
#if FPIMMEDIATE
        if (Options.strict_masm_compat == FALSE) {
          /* convert to REAL4, unless REAL8 coercion is requested */
          atofloat(&opndx.fvalue, opndx.float_tok->string_ptr, opndx.mem_type == MT_REAL8 ? 8 : 4, opndx.negative, opndx.float_tok->floattype);
          tokenarray.token = T_FINAL;
          break;
        }
#endif
      }
    }
    else {
      DebugMsg(("HllExitDir stack error\n"));
      return(EmitError(MISSING_OPERATOR_IN_EXPRESSION));
    }
    if (!hll->pcases) {
      if (casen > 56) {
        hll->pcases = LclAlloc(sizeof(int) * casen);
        hll->plabels = LclAlloc(sizeof(uint_16) * casen);
      }
      else {
        hll->pcases = LclAlloc(sizeof(int) * 56);
        hll->plabels = LclAlloc(sizeof(uint_16) * 56);
      }
    }
    hll->pcases[hll->casecnt] = opndx.value;
    myatoi128(buff + 2, dst, 16, 4);
    n = dst[0];
    hll->plabels[hll->casecnt] = (uint_16)n;
    hll->casecnt++;
    break;
Cod-Father

nidud

#108
deleted

nidud

#109
deleted

habran

You are correct, I was not aware of that.
So, in that case x64 can accept 8 chars as a constant, like:
  mov rax, "astrings"
I will see if I can rework x64 to accept eax and rax depending on a constant size.
I still have to make it able to accept 1 or 2 cases.
I am not clear with your last post, what do you mean exactly
Cod-Father

nidud

#111
deleted

habran

I don't like the idea of using a linked list, it would take more memory as well as slow down everything.
I have already prepared everything for x64 cases and it is not difficult to add one more flag to hll_item (hll->csize)
I am planing to use EvalOperand() in the .SWITCH entry, which will tell me everything abut a parameter.
I am thinking about more sophisticated use of the .SWITCH entry

I have also solved the problem with one or two cases.



Cod-Father

habran

I have a great news :t
Not that I succeeded to implement x64 constants, REAL8, "constants", 'ABCD' ...
but I succeeded to fix /Zi for x86 :bgrin:
Now everything works flawlessly 8)

We will upload it tonight or tomorrow, as soon as Johnsa get time to build it all
Cod-Father

hutch--

habran,

There is something I should have added, there is no reason not to have "break" available as it can be used for conditional exit to the next level down. A modernised "switch" is clean and tidy but if in one "case" statement  there is a conditional test where one option is to exit the current level switch block, break is a clean and tidy way to do it. In mnemonics its just a jump to the end label for the current switch block.

habran

Cod-Father

qWord

... all that discussion about a feature that can implemented as macro.

BTW:  the repo needs more than 100MB because of broken ignore-file (seems like a good candidate for git's "nuclear option").
MREAL macros - when you need floating point arithmetic while assembling!

habran

Quote from: qWord on April 28, 2016, 10:10:34 AM
... all that discussion about a feature that can implemented as macro.
You are so right qWord, we could survive even without that macro :biggrin:
People could survive even without programming (I am excepted), my mum is already 87 and newer did one line of programming :bgrin:
My granny lived stunning 96 years without even knowing that programming exists, not to mention that she died without knowing who is Leonardo da Vinchi, Socrates, Aristotle or even Frank Sinatra, she only knew about Jesus Christ as much as she was told. She would probably stay alive for maybe another 50 years, but she was bored to death because she was not able to do gardening any more so she just died of boredom :(
I was wondering, if she knew about that .SWITCH feature, would she decide to stay in this world a little bit longer 8)
Cod-Father

LiaoMi

Hallo,

I've got a construction problem in this version of code

hook_mem64 proc uc_:ptr qword, typ_:ptr qword, adr_:ptr qword, size_:ptr qword, value_:ptr qword, user_data_:ptr qword ;


mov r10, size_
mov r11, adr_
                mov rax, typ_
.switch rax
   .case UC_MEM_READ
                mov r8d, r9d
lea rcx, Memory_beingREAD ; ">>> Memory is being READ at 0x%llX, dat"...
mov rdx, r11
call printf_PE
;pop rdx
   .break
   .case UC_MEM_WRITE
                mov r9, value_
lea rcx, Memory_beingWRITE ; ">>> Memory is being WRITE at 0x%llX, da"...
mov r8d, r10d
mov rdx, r11
call printf_PE
   .break
     
.endswitch
ret
hook_mem64 endp


Error occurs here
Quote00007FF66A8B16A0
, where after the jump in
Quote00007FF66A8B16AB
,
Quote00007FF66A8B16A0 | 52  | push rdx
no return will be fulfilled, in the stack will be the extra data, and the program closes with an error, a temporary correction is made so - pop rdx written in
Quote.case UC_MEM_READ
. Compiler Options

Quote.686
.MMX
.XMM
.x64

option casemap:none
option win64:11; win64:3
option frame:auto
option stackbase:rsp

That's my fault? Or is it a build error?

00007FF66A8B1649 | 48 89 54 24 10                 | mov qword ptr ss:[rsp+10],rdx                          |
00007FF66A8B164E | 4C 89 44 24 18                 | mov qword ptr ss:[rsp+18],r8                           |
00007FF66A8B1653 | 4C 89 4C 24 20                 | mov qword ptr ss:[rsp+20],r9                           |
00007FF66A8B1658 | 4C 8B 54 24 20                 | mov r10,qword ptr ss:[rsp+20]                          |
00007FF66A8B165D | 4C 8B 5C 24 18                 | mov r11,qword ptr ss:[rsp+18]                          |
00007FF66A8B1662 | 48 8B 44 24 10                 | mov rax,qword ptr ss:[rsp+10]                          |
00007FF66A8B1667 | EB 37                          | jmp win64test.7FF66A8B16A0                             |
00007FF66A8B1669 | 45 8B C1                       | mov r8d,r9d                                            |
00007FF66A8B166C | 48 8D 0D 1C 1C 00 00           | lea rcx,qword ptr ds:[7FF66A8B328F]                    | 7FF66A8B328F:">>> Memory is being READ at 0x%llX, data size = %u\n"
00007FF66A8B1673 | 49 8B D3                       | mov rdx,r11                                            |
00007FF66A8B1676 | E8 56 00 00 00                 | call win64test.7FF66A8B16D1                            |
00007FF66A8B167B | 5A                             | pop rdx                                                |
00007FF66A8B167C | EB 42                          | jmp win64test.7FF66A8B16C0                             |
00007FF66A8B167E | EB 40                          | jmp win64test.7FF66A8B16C0                             |
00007FF66A8B1680 | 4C 8B 4C 24 28                 | mov r9,qword ptr ss:[rsp+28]                           |
00007FF66A8B1685 | 48 8D 0D 37 1C 00 00           | lea rcx,qword ptr ds:[7FF66A8B32C3]                    | 7FF66A8B32C3:">>> Memory is being WRITE at 0x%llX, data size = %u, data value = 0x%llX\n"
00007FF66A8B168C | 45 8B C2                       | mov r8d,r10d                                           |
00007FF66A8B168F | 49 8B D3                       | mov rdx,r11                                            |
00007FF66A8B1692 | E8 3A 00 00 00                 | call win64test.7FF66A8B16D1                            |
00007FF66A8B1697 | EB 27                          | jmp win64test.7FF66A8B16C0                             |
00007FF66A8B1699 | EB 25                          | jmp win64test.7FF66A8B16C0                             |
00007FF66A8B169B | 0F 1F 44 00 00                 | nop dword ptr ds:[rax+rax]                             |
00007FF66A8B16A0 | 52                             | push rdx                                               |
00007FF66A8B16A1 | 48 C7 C2 10 00 00 00           | mov rdx,10                                             |
00007FF66A8B16A8 | 48 3B C2                       | cmp rax,rdx                                            |
00007FF66A8B16AB | 74 BC                          | je win64test.7FF66A8B1669                              |
00007FF66A8B16AD | 48 C7 C2 11 00 00 00           | mov rdx,11                                             |
00007FF66A8B16B4 | 48 3B C2                       | cmp rax,rdx                                            |
00007FF66A8B16B7 | 5A                             | pop rdx                                                |
00007FF66A8B16B8 | 74 C6                          | je win64test.7FF66A8B1680                              |
00007FF66A8B16BA | EB 04                          | jmp win64test.7FF66A8B16C0                             |
00007FF66A8B16BC | 0F 1F 40 00                    | nop dword ptr ds:[rax]                                 |
00007FF66A8B16C0 | 48 83 C4 00                    | add rsp,0                                              |
00007FF66A8B16C4 | C3                             | ret                                                    |


Regards

LiaoMi

Hallo,

perfect timing  :biggrin:, today's hjwasm update no longer causes an error  :t

Regards!