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:
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);
}