Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  nodelist  faq  login

Sex, Drugs & Linux Rules -- MaDsen Wikholm, mwikholm@at8.abo.fi


programming / comp.lang.asm.x86 / Re: CMP flags going wrong in my emu?

SubjectAuthor
* CMP flags going wrong in my emu?luserdroog
+- Re: CMP flags going wrong in my emu?luserdroog
+* Re: CMP flags going wrong in my emu?Alexei A. Frounze
|+* Re: CMP flags going wrong in my emu?luserdroog
||`* Re: CMP flags going wrong in my emu?luserdroog
|| `* Re: CMP flags going wrong in my emu?wolfgang kern
||  `- Re: CMP flags going wrong in my emu?luserdroog
|`* Re: CMP flags going wrong in my emu?luserdroog
| `* Re: CMP flags going wrong in my emu?Alexei A. Frounze
|  +* Re: CMP flags going wrong in my emu?luserdroog
|  |`* Re: CMP flags going wrong in my emu?Alexei A. Frounze
|  | `- Re: CMP flags going wrong in my emu?luserdroog
|  `* Re: CMP flags going wrong in my emu?luserdroog
|   `- Re: CMP flags going wrong in my emu?Alexei A. Frounze
`- Re: CMP flags going wrong in my emu?olcott

1
Subject: CMP flags going wrong in my emu?
From: luserdroog
Newsgroups: comp.lang.asm.x86
Organization: A noiseless patient Spider
Date: Mon, 14 Sep 2020 04:13 UTC
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: luser.dr...@nospicedham.gmail.com (luserdroog)
Newsgroups: comp.lang.asm.x86
Subject: CMP flags going wrong in my emu?
Date: Sun, 13 Sep 2020 21:13:34 -0700 (PDT)
Organization: A noiseless patient Spider
Lines: 33
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <79353012-efc1-4777-aa3d-b31a0df11207o@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Date: Mon, 14 Sep 2020 04:13:34 +0000
Injection-Info: reader02.eternal-september.org; posting-host="9e00f04af3dabf04fff5f1576d20d144";
logging-data="18982"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19+tMOnPymY8gUaxCr18B+gFtl834RSd9w="
User-Agent: G2/1.0
Cancel-Lock: sha1:/gNToTu7kOMpoqGyfB6qKXePIyc=
View all headers
I'm trying to fill out my toy forth interpreter and I think I have
a bug in my emulator for the CMP instruction and therefore probably
also SUB and SBB.

The problem is showing up in my comparator functions
CODE(<,     less,      POP(CX),POP(BX), MOVAXI(0xff,0xff), CMP(,R,BX,CX), JL,2,INC_(R,AX), PUSH(AX))
CODE(>,     more,      POP(CX),POP(BX), MOVAXI(0xff,0xff), CMP(,R,BX,CX), JG,2,INC_(R,AX), PUSH(AX))

When I test it with

WORD(test2a,test2a,    enter, one, ten, less, dot,
                              one, ten, more, dot, ok)

no matter how I permute the arguments -- changing BX and CX in the CMP
instruction, or in the POP order, or in the test script -- the results
never change.

  0 -1 OK

Here's the stack trace on the first one.

ax:ffff cx:000a dx:0000 bx:0001 sp:f000 bp:1ffc si:0e1a di:0000 ip:046d fl:0004 NC NO NS NZ
3b(073) cmpwt: d9(331) x:1 y:10 ->fffffff7
ax:ffff cx:000a dx:0000 bx:0001 sp:f000 bp:1ffc si:0e1a di:0000 ip:046f fl:0891 CA OV SN NZ
7c(174) jl: 02(002) <0>
ax:ffff cx:000a dx:0000 bx:0001 sp:f000 bp:1ffc si:0e1a di:0000 ip:0471 fl:0891 CA OV SN NZ
ff(377) grp2w: c0(300) INC ->0000

The CMP produces fffffff7 which seems like the correct subtraction
extended to 32 bits. But the JL isn't taken.

Are my flags wrong after the cmpwt instruction?



Subject: Re: CMP flags going wrong in my emu?
From: luserdroog
Newsgroups: comp.lang.asm.x86
Organization: A noiseless patient Spider
Date: Mon, 14 Sep 2020 04:49 UTC
References: 1
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: luser.dr...@nospicedham.gmail.com (luserdroog)
Newsgroups: comp.lang.asm.x86
Subject: Re: CMP flags going wrong in my emu?
Date: Sun, 13 Sep 2020 21:49:26 -0700 (PDT)
Organization: A noiseless patient Spider
Lines: 20
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <17644e41-db78-4168-8f63-11f202f835c1o@googlegroups.com>
References: <79353012-efc1-4777-aa3d-b31a0df11207o@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Date: Mon, 14 Sep 2020 04:49:27 +0000
Injection-Info: reader02.eternal-september.org; posting-host="9e00f04af3dabf04fff5f1576d20d144";
logging-data="25591"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+8qsWhxBvPm7EccBrSTQPDShFqLxA11aA="
User-Agent: G2/1.0
Cancel-Lock: sha1:jGTVdLz5hRJb6gWT5U9IPdjA7ZI=
View all headers
On Sunday, September 13, 2020 at 11:20:43 PM UTC-5, luserdroog wrote:

Here's the stack trace on the first one.

ax:ffff cx:000a dx:0000 bx:0001 sp:f000 bp:1ffc si:0e1a di:0000 ip:046d fl:0004 NC NO NS NZ
3b(073) cmpwt: d9(331) x:1 y:10 ->fffffff7
ax:ffff cx:000a dx:0000 bx:0001 sp:f000 bp:1ffc si:0e1a di:0000 ip:046f fl:0891 CA OV SN NZ
7c(174) jl: 02(002) <0>
ax:ffff cx:000a dx:0000 bx:0001 sp:f000 bp:1ffc si:0e1a di:0000 ip:0471 fl:0891 CA OV SN NZ
ff(377) grp2w: c0(300) INC ->0000

The CMP produces fffffff7 which seems like the correct subtraction
extended to 32 bits. But the JL isn't taken.

Are my flags wrong after the cmpwt instruction?

I'm pretty sure this *is* wrong. I think I should have Carry but No
Overflow. The upper half is clearly the sign extension of the low 15
bits so it should not be considered an overflow, I think.



Subject: Re: CMP flags going wrong in my emu?
From: Alexei A. Frounze
Newsgroups: comp.lang.asm.x86
Organization: A noiseless patient Spider
Date: Mon, 14 Sep 2020 05:54 UTC
References: 1
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: alexfrun...@nospicedham.gmail.com (Alexei A. Frounze)
Newsgroups: comp.lang.asm.x86
Subject: Re: CMP flags going wrong in my emu?
Date: Sun, 13 Sep 2020 22:54:15 -0700 (PDT)
Organization: A noiseless patient Spider
Lines: 73
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <f95ea1ca-4332-491d-a706-b24a2dc66fb0o@googlegroups.com>
References: <79353012-efc1-4777-aa3d-b31a0df11207o@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Date: Mon, 14 Sep 2020 05:54:16 +0000
Injection-Info: reader02.eternal-september.org; posting-host="9e00f04af3dabf04fff5f1576d20d144";
logging-data="12352"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18dG3YPMzFXFBec9RXphP1gsyJ6N6+gtus="
User-Agent: G2/1.0
Cancel-Lock: sha1:MaULrFRzAT0CZEu9wE8LGeXtEko=
View all headers
On Sunday, September 13, 2020 at 9:20:43 PM UTC-7, luserdroog wrote:
I'm trying to fill out my toy forth interpreter and I think I have
a bug in my emulator for the CMP instruction and therefore probably
also SUB and SBB.

The problem is showing up in my comparator functions
CODE(<,     less,      POP(CX),POP(BX), MOVAXI(0xff,0xff), CMP(,R,BX,CX), JL,2,INC_(R,AX), PUSH(AX))
CODE(>,     more,      POP(CX),POP(BX), MOVAXI(0xff,0xff), CMP(,R,BX,CX), JG,2,INC_(R,AX), PUSH(AX))

When I test it with

WORD(test2a,test2a,    enter, one, ten, less, dot,
                              one, ten, more, dot, ok)

no matter how I permute the arguments -- changing BX and CX in the CMP
instruction, or in the POP order, or in the test script -- the results
never change.

  0 -1 OK

Here's the stack trace on the first one.

ax:ffff cx:000a dx:0000 bx:0001 sp:f000 bp:1ffc si:0e1a di:0000 ip:046d fl:0004 NC NO NS NZ
3b(073) cmpwt: d9(331) x:1 y:10 ->fffffff7
ax:ffff cx:000a dx:0000 bx:0001 sp:f000 bp:1ffc si:0e1a di:0000 ip:046f fl:0891 CA OV SN NZ
7c(174) jl: 02(002) <0>
ax:ffff cx:000a dx:0000 bx:0001 sp:f000 bp:1ffc si:0e1a di:0000 ip:0471 fl:0891 CA OV SN NZ
ff(377) grp2w: c0(300) INC ->0000

The CMP produces fffffff7 which seems like the correct subtraction
extended to 32 bits. But the JL isn't taken.

Are my flags wrong after the cmpwt instruction?

If you have to ask, it's quite possible.
Care to show your code for add/adc, sub/sbb/cmp?

I don't know why you're sign-extending 16-bit values
to 32 bits when performing a 16-bit operation.
It may contribute to the problem by itself.

Before you ask a question like this you should explain
your syntax a little bit. For example, in

  CMP(,R,BX,CX)

I don't know if the operand order is the same as in the
intel/AMD x86 manual or the opposite like in the AT&T
assembly syntax.

Supposing the order is like in the intel syntax and you're doing:

  CMP BX, CX

when BX=1 and CX=0xA, you should get:

  difference = 0xFFF7 (unsigned) or -9 (signed), not stored anywhere

  FLAGS.SF=1 (most significant (AKA sign) bit of the above difference)

  FLAGS.ZF=0 (the above difference isn't 0)

  FLAGS.CF=1 (in unsigned comparison 1 < 0xA holds true)

  FLAGS.OF=0 (mathematical difference: 1 - 0xA = -9, correctly represented)

JL will jump when SF!=OF. This should be the case here.

It's very likely that your signed overflow computation is busted.
This may help: https://stackoverflow.com/a/8037485/968261

Alex



Subject: Re: CMP flags going wrong in my emu?
From: luserdroog
Newsgroups: comp.lang.asm.x86
Organization: A noiseless patient Spider
Date: Mon, 14 Sep 2020 06:18 UTC
References: 1 2
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: luser.dr...@nospicedham.gmail.com (luserdroog)
Newsgroups: comp.lang.asm.x86
Subject: Re: CMP flags going wrong in my emu?
Date: Sun, 13 Sep 2020 23:18:01 -0700 (PDT)
Organization: A noiseless patient Spider
Lines: 82
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <6e499cf0-8e55-41f4-b6a5-f0fa91be7fa5o@googlegroups.com>
References: <79353012-efc1-4777-aa3d-b31a0df11207o@googlegroups.com> <f95ea1ca-4332-491d-a706-b24a2dc66fb0o@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Date: Mon, 14 Sep 2020 06:18:01 +0000
Injection-Info: reader02.eternal-september.org; posting-host="9e00f04af3dabf04fff5f1576d20d144";
logging-data="16857"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19BKFxSMoEaoABH5bz/bN9y50d975JPo+c="
User-Agent: G2/1.0
Cancel-Lock: sha1:PITOX6A0ssyRzovexUlqDHpV4/4=
View all headers
On Monday, September 14, 2020 at 1:05:56 AM UTC-5, Alexei A. Frounze wrote:
On Sunday, September 13, 2020 at 9:20:43 PM UTC-7, luserdroog wrote:
I'm trying to fill out my toy forth interpreter and I think I have
a bug in my emulator for the CMP instruction and therefore probably
also SUB and SBB.

The problem is showing up in my comparator functions
CODE(<,     less,      POP(CX),POP(BX), MOVAXI(0xff,0xff), CMP(,R,BX,CX), JL,2,INC_(R,AX), PUSH(AX))
CODE(>,     more,      POP(CX),POP(BX), MOVAXI(0xff,0xff), CMP(,R,BX,CX), JG,2,INC_(R,AX), PUSH(AX))

When I test it with

WORD(test2a,test2a,    enter, one, ten, less, dot,
                              one, ten, more, dot, ok)

no matter how I permute the arguments -- changing BX and CX in the CMP
instruction, or in the POP order, or in the test script -- the results
never change.

  0 -1 OK

Here's the stack trace on the first one.

ax:ffff cx:000a dx:0000 bx:0001 sp:f000 bp:1ffc si:0e1a di:0000 ip:046d fl:0004 NC NO NS NZ
3b(073) cmpwt: d9(331) x:1 y:10 ->fffffff7
ax:ffff cx:000a dx:0000 bx:0001 sp:f000 bp:1ffc si:0e1a di:0000 ip:046f fl:0891 CA OV SN NZ
7c(174) jl: 02(002) <0>
ax:ffff cx:000a dx:0000 bx:0001 sp:f000 bp:1ffc si:0e1a di:0000 ip:0471 fl:0891 CA OV SN NZ
ff(377) grp2w: c0(300) INC ->0000

The CMP produces fffffff7 which seems like the correct subtraction
extended to 32 bits. But the JL isn't taken.

Are my flags wrong after the cmpwt instruction?

If you have to ask, it's quite possible.
Care to show your code for add/adc, sub/sbb/cmp?

I don't know why you're sign-extending 16-bit values
to 32 bits when performing a 16-bit operation.
It may contribute to the problem by itself.

Before you ask a question like this you should explain
your syntax a little bit. For example, in

  CMP(,R,BX,CX)

I don't know if the operand order is the same as in the
intel/AMD x86 manual or the opposite like in the AT&T
assembly syntax.

It's a custom macro syntax which targets the "from" forms R selects
MOD=3 (register to register) and BX is in the REG field and CX is in
the REG/MEM field. So, as correctly surmised below, BX is the
Destination and CX is the Source. So the comparison should be the
same as the subtraction BX-CX.

Supposing the order is like in the intel syntax and you're doing:

  CMP BX, CX

when BX=1 and CX=0xA, you should get:

  difference = 0xFFF7 (unsigned) or -9 (signed), not stored anywhere

  FLAGS.SF=1 (most significant (AKA sign) bit of the above difference)

  FLAGS.ZF=0 (the above difference isn't 0)

  FLAGS.CF=1 (in unsigned comparison 1 < 0xA holds true)

  FLAGS.OF=0 (mathematical difference: 1 - 0xA = -9, correctly represented)

JL will jump when SF!=OF. This should be the case here.

It's very likely that your signed overflow computation is busted.
This may help: https://stackoverflow.com/a/8037485/968261

Alex

Thanks. Yep, it's that stupid overflow again lol.



Subject: Re: CMP flags going wrong in my emu?
From: luserdroog
Newsgroups: comp.lang.asm.x86
Organization: A noiseless patient Spider
Date: Mon, 14 Sep 2020 06:50 UTC
References: 1 2
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: luser.dr...@nospicedham.gmail.com (luserdroog)
Newsgroups: comp.lang.asm.x86
Subject: Re: CMP flags going wrong in my emu?
Date: Sun, 13 Sep 2020 23:50:16 -0700 (PDT)
Organization: A noiseless patient Spider
Lines: 58
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <bdaeae60-480b-4af6-ab55-7511fb4345b2o@googlegroups.com>
References: <79353012-efc1-4777-aa3d-b31a0df11207o@googlegroups.com> <f95ea1ca-4332-491d-a706-b24a2dc66fb0o@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Date: Mon, 14 Sep 2020 06:50:17 +0000
Injection-Info: reader02.eternal-september.org; posting-host="9e00f04af3dabf04fff5f1576d20d144";
logging-data="25721"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18St+KpEtIBxSxFDWmw+oInnYyUuYBF9hM="
User-Agent: G2/1.0
Cancel-Lock: sha1:3xN105fwDb1uvkBQDNQRUOLCFqs=
View all headers
On Monday, September 14, 2020 at 1:05:56 AM UTC-5, Alexei A. Frounze wrote:
On Sunday, September 13, 2020 at 9:20:43 PM UTC-7, luserdroog wrote:
Here's the stack trace on the first one.

ax:ffff cx:000a dx:0000 bx:0001 sp:f000 bp:1ffc si:0e1a di:0000 ip:046d fl:0004 NC NO NS NZ
3b(073) cmpwt: d9(331) x:1 y:10 ->fffffff7
ax:ffff cx:000a dx:0000 bx:0001 sp:f000 bp:1ffc si:0e1a di:0000 ip:046f fl:0891 CA OV SN NZ
7c(174) jl: 02(002) <0>
ax:ffff cx:000a dx:0000 bx:0001 sp:f000 bp:1ffc si:0e1a di:0000 ip:0471 fl:0891 CA OV SN NZ
ff(377) grp2w: c0(300) INC ->0000

The CMP produces fffffff7 which seems like the correct subtraction
extended to 32 bits. But the JL isn't taken.

Are my flags wrong after the cmpwt instruction?

If you have to ask, it's quite possible.
Care to show your code for add/adc, sub/sbb/cmp?


The code is at:

https://github.com/luser-dr00g/8086/blob/fd410940a9fd226dea5d70a8e3264fabee4595f3/a8086.c

and an explanation of the code is at:

https://codegolf.stackexchange.com/a/52902/2381

(this includes a fully preprocessed and indent-ed addbt
(add byte "to") operator function.

The CMP operator sets the destination pointer to a sink,
loads variables x and y from dest and source, and calls
SUB which does ... hang on, computer rebooted. now I gotta
delete the X.lock to fire up emacs ... ah, that's better...
SUB does

#define SUB z=d?x-y:y-x; LOGFLAGS MATHFLAGS RESULT

where the flags are set with

    // flags set by logical operators
#define LOGFLAGS  *fl=0; \
                  *fl |= ( (z&(w?0x8000:0x80))           ?SF:0) \
                       | ( (z&(w?0xffff:0xff))==0        ?ZF:0) ;

    // additional flags set by math operators
#define MATHFLAGS *fl |= ( (z&(w?0xffff0000:0xff00))     ?CF:0) \
                       | ( ((z^x)&(z^y)&(w?0x8000:0x80)) ?OF:0) \
                       | ( ((x^y^z)&0x10)                ?AF:0); \
                       SETPF

I don't know where I came up with that expression for OF.
It's gibberish to me now.






Subject: Re: CMP flags going wrong in my emu?
From: Alexei A. Frounze
Newsgroups: comp.lang.asm.x86
Organization: A noiseless patient Spider
Date: Mon, 14 Sep 2020 08:41 UTC
References: 1 2 3
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: alexfrun...@nospicedham.gmail.com (Alexei A. Frounze)
Newsgroups: comp.lang.asm.x86
Subject: Re: CMP flags going wrong in my emu?
Date: Mon, 14 Sep 2020 01:41:35 -0700 (PDT)
Organization: A noiseless patient Spider
Lines: 29
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <5c21cbc7-88c5-4d7a-809c-adc74d824c61o@googlegroups.com>
References: <79353012-efc1-4777-aa3d-b31a0df11207o@googlegroups.com>
<f95ea1ca-4332-491d-a706-b24a2dc66fb0o@googlegroups.com> <bdaeae60-480b-4af6-ab55-7511fb4345b2o@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Date: Mon, 14 Sep 2020 08:41:36 +0000
Injection-Info: reader02.eternal-september.org; posting-host="9e00f04af3dabf04fff5f1576d20d144";
logging-data="32052"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18n9gEMZx21ugJ0/h8lJDAxu17VDqjEDNg="
User-Agent: G2/1.0
Cancel-Lock: sha1:Z6FYuHzVlUX1VMHF4k+auIcMwT4=
View all headers
On Sunday, September 13, 2020 at 11:51:13 PM UTC-7, luserdroog wrote:
    // additional flags set by math operators
#define MATHFLAGS *fl |= ( (z&(w?0xffff0000:0xff00))     ?CF:0) \
                       | ( ((z^x)&(z^y)&(w?0x8000:0x80)) ?OF:0) \
                       | ( ((x^y^z)&0x10)                ?AF:0); \
                       SETPF

I don't know where I came up with that expression for OF.
It's gibberish to me now.

It's making sure that the result's sign is the same
as the signs of x and y. If that isn't true, OF gets set.
That works for addition, z = x + y,
but not subtraction, z = x - y.
Unless you exchange things a bit...

add: z = x + y
(z^x)&(z^y)&...

sub: z = x - y
OR, speaking in terms of addition...
sub: x = z + y
(x^z)&(x^y)&...

IOW, for the purposes of OF calculation you need to
exchange x and z in that formula of yours.

Alex



Subject: Re: CMP flags going wrong in my emu?
From: luserdroog
Newsgroups: comp.lang.asm.x86
Organization: A noiseless patient Spider
Date: Mon, 14 Sep 2020 09:38 UTC
References: 1 2 3 4
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: luser.dr...@nospicedham.gmail.com (luserdroog)
Newsgroups: comp.lang.asm.x86
Subject: Re: CMP flags going wrong in my emu?
Date: Mon, 14 Sep 2020 02:38:07 -0700 (PDT)
Organization: A noiseless patient Spider
Lines: 33
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <daf77d92-4189-4558-9d1a-3560f5c7d25bo@googlegroups.com>
References: <79353012-efc1-4777-aa3d-b31a0df11207o@googlegroups.com>
<f95ea1ca-4332-491d-a706-b24a2dc66fb0o@googlegroups.com> <bdaeae60-480b-4af6-ab55-7511fb4345b2o@googlegroups.com>
<5c21cbc7-88c5-4d7a-809c-adc74d824c61o@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Date: Mon, 14 Sep 2020 09:38:07 +0000
Injection-Info: reader02.eternal-september.org; posting-host="9e00f04af3dabf04fff5f1576d20d144";
logging-data="20445"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX194XLmHsz/ftoTd42W8zKUQzsnzBvddGb4="
User-Agent: G2/1.0
Cancel-Lock: sha1:n1hFZWFmvPr3loq3neu+Mck1UFQ=
View all headers
On Monday, September 14, 2020 at 3:51:24 AM UTC-5, Alexei A. Frounze wrote:
On Sunday, September 13, 2020 at 11:51:13 PM UTC-7, luserdroog wrote:
    // additional flags set by math operators
#define MATHFLAGS *fl |= ( (z&(w?0xffff0000:0xff00))     ?CF:0) \
                       | ( ((z^x)&(z^y)&(w?0x8000:0x80)) ?OF:0) \
                       | ( ((x^y^z)&0x10)                ?AF:0); \
                       SETPF

I don't know where I came up with that expression for OF.
It's gibberish to me now.

It's making sure that the result's sign is the same
as the signs of x and y. If that isn't true, OF gets set.
That works for addition, z = x + y,
but not subtraction, z = x - y.
Unless you exchange things a bit...

add: z = x + y
(z^x)&(z^y)&...

sub: z = x - y
OR, speaking in terms of addition...
sub: x = z + y
(x^z)&(x^y)&...

IOW, for the purposes of OF calculation you need to
exchange x and z in that formula of yours.

Alex

Thanks a bunch! It works great now. My forth can now
print numbers in any base from 2 to 36.



Subject: Re: CMP flags going wrong in my emu?
From: Alexei A. Frounze
Newsgroups: comp.lang.asm.x86
Organization: A noiseless patient Spider
Date: Mon, 14 Sep 2020 10:34 UTC
References: 1 2 3 4 5
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: alexfrun...@nospicedham.gmail.com (Alexei A. Frounze)
Newsgroups: comp.lang.asm.x86
Subject: Re: CMP flags going wrong in my emu?
Date: Mon, 14 Sep 2020 03:34:17 -0700 (PDT)
Organization: A noiseless patient Spider
Lines: 41
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <779bebff-3c41-456e-9f99-c9ea95f25a6bo@googlegroups.com>
References: <79353012-efc1-4777-aa3d-b31a0df11207o@googlegroups.com>
<f95ea1ca-4332-491d-a706-b24a2dc66fb0o@googlegroups.com> <bdaeae60-480b-4af6-ab55-7511fb4345b2o@googlegroups.com>
<5c21cbc7-88c5-4d7a-809c-adc74d824c61o@googlegroups.com> <daf77d92-4189-4558-9d1a-3560f5c7d25bo@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Date: Mon, 14 Sep 2020 10:34:18 +0000
Injection-Info: reader02.eternal-september.org; posting-host="9e00f04af3dabf04fff5f1576d20d144";
logging-data="3969"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Epe5AYhp9rB4Dv0D9G9rt9iWZxGZz5so="
User-Agent: G2/1.0
Cancel-Lock: sha1:1D/lI/u62Y6TAQJOKbFJSrunov0=
View all headers
On Monday, September 14, 2020 at 2:51:34 AM UTC-7, luserdroog wrote:
On Monday, September 14, 2020 at 3:51:24 AM UTC-5, Alexei A. Frounze wrote:
On Sunday, September 13, 2020 at 11:51:13 PM UTC-7, luserdroog wrote:
    // additional flags set by math operators
#define MATHFLAGS *fl |= ( (z&(w?0xffff0000:0xff00))     ?CF:0) \
                       | ( ((z^x)&(z^y)&(w?0x8000:0x80)) ?OF:0) \
                       | ( ((x^y^z)&0x10)                ?AF:0); \
                       SETPF

I don't know where I came up with that expression for OF.
It's gibberish to me now.

It's making sure that the result's sign is the same
as the signs of x and y. If that isn't true, OF gets set.
That works for addition, z = x + y,
but not subtraction, z = x - y.
Unless you exchange things a bit...

add: z = x + y
(z^x)&(z^y)&...

sub: z = x - y
OR, speaking in terms of addition...
sub: x = z + y
(x^z)&(x^y)&...

IOW, for the purposes of OF calculation you need to
exchange x and z in that formula of yours.

Alex

Thanks a bunch! It works great now. My forth can now
print numbers in any base from 2 to 36.

Sorry, I hit "send" too soon without a clarification.

You need to exchange x with z in MATHFLAGS for sub only.
I think now you have add broken.

Alex



Subject: Re: CMP flags going wrong in my emu?
From: luserdroog
Newsgroups: comp.lang.asm.x86
Organization: A noiseless patient Spider
Date: Mon, 14 Sep 2020 16:53 UTC
References: 1 2 3 4 5 6
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: luser.dr...@nospicedham.gmail.com (luserdroog)
Newsgroups: comp.lang.asm.x86
Subject: Re: CMP flags going wrong in my emu?
Date: Mon, 14 Sep 2020 09:53:55 -0700 (PDT)
Organization: A noiseless patient Spider
Lines: 44
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <88f410b6-e117-43a6-97d8-8e299ee4de75o@googlegroups.com>
References: <79353012-efc1-4777-aa3d-b31a0df11207o@googlegroups.com>
<f95ea1ca-4332-491d-a706-b24a2dc66fb0o@googlegroups.com> <bdaeae60-480b-4af6-ab55-7511fb4345b2o@googlegroups.com>
<5c21cbc7-88c5-4d7a-809c-adc74d824c61o@googlegroups.com> <daf77d92-4189-4558-9d1a-3560f5c7d25bo@googlegroups.com>
<779bebff-3c41-456e-9f99-c9ea95f25a6bo@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Date: Mon, 14 Sep 2020 16:53:55 +0000
Injection-Info: reader02.eternal-september.org; posting-host="9e00f04af3dabf04fff5f1576d20d144";
logging-data="21779"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18XS/fZA3/giODAbKEL/J0xY02j9LAJVH0="
User-Agent: G2/1.0
Cancel-Lock: sha1:lLPFdLzoZPlPfsWy+FQnye7dDlM=
View all headers
On Monday, September 14, 2020 at 5:36:43 AM UTC-5, Alexei A. Frounze wrote:
On Monday, September 14, 2020 at 2:51:34 AM UTC-7, luserdroog wrote:
On Monday, September 14, 2020 at 3:51:24 AM UTC-5, Alexei A. Frounze wrote:
On Sunday, September 13, 2020 at 11:51:13 PM UTC-7, luserdroog wrote:
    // additional flags set by math operators
#define MATHFLAGS *fl |= ( (z&(w?0xffff0000:0xff00))     ?CF:0) \
                       | ( ((z^x)&(z^y)&(w?0x8000:0x80)) ?OF:0) \
                       | ( ((x^y^z)&0x10)                ?AF:0); \
                       SETPF

I don't know where I came up with that expression for OF.
It's gibberish to me now.

It's making sure that the result's sign is the same
as the signs of x and y. If that isn't true, OF gets set.
That works for addition, z = x + y,
but not subtraction, z = x - y.
Unless you exchange things a bit...

add: z = x + y
(z^x)&(z^y)&...

sub: z = x - y
OR, speaking in terms of addition...
sub: x = z + y
(x^z)&(x^y)&...

IOW, for the purposes of OF calculation you need to
exchange x and z in that formula of yours.

Alex

Thanks a bunch! It works great now. My forth can now
print numbers in any base from 2 to 36.

Sorry, I hit "send" too soon without a clarification.

You need to exchange x with z in MATHFLAGS for sub only.
I think now you have add broken.


Ok. Thanks again. I'm parameterizing it so there's a separate formula
for ADDFLAGS vs SUBFLAGS.



Subject: Re: CMP flags going wrong in my emu?
From: luserdroog
Newsgroups: comp.lang.asm.x86
Organization: A noiseless patient Spider
Date: Mon, 14 Sep 2020 17:15 UTC
References: 1 2 3
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: luser.dr...@nospicedham.gmail.com (luserdroog)
Newsgroups: comp.lang.asm.x86
Subject: Re: CMP flags going wrong in my emu?
Date: Mon, 14 Sep 2020 10:15:06 -0700 (PDT)
Organization: A noiseless patient Spider
Lines: 26
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <6cc81955-fcd7-4cdb-aa73-0a2ce8d3a802o@googlegroups.com>
References: <79353012-efc1-4777-aa3d-b31a0df11207o@googlegroups.com>
<f95ea1ca-4332-491d-a706-b24a2dc66fb0o@googlegroups.com> <6e499cf0-8e55-41f4-b6a5-f0fa91be7fa5o@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Date: Mon, 14 Sep 2020 17:15:06 +0000
Injection-Info: reader02.eternal-september.org; posting-host="9e00f04af3dabf04fff5f1576d20d144";
logging-data="27786"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1951MYUwc4ZRuB13pER3e3t82VKBUl+D4c="
User-Agent: G2/1.0
Cancel-Lock: sha1:uYev68fLGZc8CFCa39MkPTF+aY4=
View all headers
On Monday, September 14, 2020 at 1:21:04 AM UTC-5, luserdroog wrote:
On Monday, September 14, 2020 at 1:05:56 AM UTC-5, Alexei A. Frounze wrote:
On Sunday, September 13, 2020 at 9:20:43 PM UTC-7, luserdroog wrote:

Before you ask a question like this you should explain
your syntax a little bit. For example, in

  CMP(,R,BX,CX)

I don't know if the operand order is the same as in the
intel/AMD x86 manual or the opposite like in the AT&T
assembly syntax.

It's a custom macro syntax which targets the "from" forms R selects
MOD=3 (register to register) and BX is in the REG field and CX is in
the REG/MEM field. So, as correctly surmised below, BX is the
Destination and CX is the Source. So the comparison should be the
same as the subtraction BX-CX.


I said this wrong. These are "to" forms, not "from". The first argument
to my CMP macro can be F to create a "from" opcode or blank (as above)
to create a "to" opcode. Elsethread I mentioned the expanded operator
function listed in my codegolf answer, that should be "addbf" (the "from"
form) not "addbt". Sigh. addbf (add byte from) being opcode 0x00.



Subject: Re: CMP flags going wrong in my emu?
From: luserdroog
Newsgroups: comp.lang.asm.x86
Organization: A noiseless patient Spider
Date: Mon, 14 Sep 2020 21:31 UTC
References: 1 2 3 4
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: luser.dr...@nospicedham.gmail.com (luserdroog)
Newsgroups: comp.lang.asm.x86
Subject: Re: CMP flags going wrong in my emu?
Date: Mon, 14 Sep 2020 14:31:54 -0700 (PDT)
Organization: A noiseless patient Spider
Lines: 36
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <8cce9da5-635b-407e-9c81-34a53ffe173eo@googlegroups.com>
References: <79353012-efc1-4777-aa3d-b31a0df11207o@googlegroups.com>
<f95ea1ca-4332-491d-a706-b24a2dc66fb0o@googlegroups.com> <bdaeae60-480b-4af6-ab55-7511fb4345b2o@googlegroups.com>
<5c21cbc7-88c5-4d7a-809c-adc74d824c61o@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Date: Mon, 14 Sep 2020 21:31:54 +0000
Injection-Info: reader02.eternal-september.org; posting-host="9e00f04af3dabf04fff5f1576d20d144";
logging-data="28871"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/FLzBeVImXwBLw80vvlomwRnMyB/dAuW4="
User-Agent: G2/1.0
Cancel-Lock: sha1:An6u+b9F7j7s8dbC4bTUtaGrQyk=
View all headers
On Monday, September 14, 2020 at 3:51:24 AM UTC-5, Alexei A. Frounze wrote:
On Sunday, September 13, 2020 at 11:51:13 PM UTC-7, luserdroog wrote:
    // additional flags set by math operators
#define MATHFLAGS *fl |= ( (z&(w?0xffff0000:0xff00))     ?CF:0) \
                       | ( ((z^x)&(z^y)&(w?0x8000:0x80)) ?OF:0) \
                       | ( ((x^y^z)&0x10)                ?AF:0); \
                       SETPF

I don't know where I came up with that expression for OF.
It's gibberish to me now.

It's making sure that the result's sign is the same
as the signs of x and y. If that isn't true, OF gets set.
That works for addition, z = x + y,
but not subtraction, z = x - y.
Unless you exchange things a bit...

add: z = x + y
(z^x)&(z^y)&...

sub: z = x - y
OR, speaking in terms of addition...
sub: x = z + y
(x^z)&(x^y)&...

IOW, for the purposes of OF calculation you need to
exchange x and z in that formula of yours.

Alex

Do I also need to swap x and y if the direction is
reversed and z = y - x?
then y = z + x.
sthg like:
  ((d?x:y)^z)&(x^y)&...



Subject: Re: CMP flags going wrong in my emu?
From: Alexei A. Frounze
Newsgroups: comp.lang.asm.x86
Organization: A noiseless patient Spider
Date: Mon, 14 Sep 2020 22:51 UTC
References: 1 2 3 4 5
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: alexfrun...@nospicedham.gmail.com (Alexei A. Frounze)
Newsgroups: comp.lang.asm.x86
Subject: Re: CMP flags going wrong in my emu?
Date: Mon, 14 Sep 2020 15:51:41 -0700 (PDT)
Organization: A noiseless patient Spider
Lines: 58
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <9286cd72-47f4-4375-ac9c-d2c6bca997e4o@googlegroups.com>
References: <79353012-efc1-4777-aa3d-b31a0df11207o@googlegroups.com>
<f95ea1ca-4332-491d-a706-b24a2dc66fb0o@googlegroups.com> <bdaeae60-480b-4af6-ab55-7511fb4345b2o@googlegroups.com>
<5c21cbc7-88c5-4d7a-809c-adc74d824c61o@googlegroups.com> <8cce9da5-635b-407e-9c81-34a53ffe173eo@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Date: Mon, 14 Sep 2020 22:51:41 +0000
Injection-Info: reader02.eternal-september.org; posting-host="06cd29ac3c2e6e689506469e787f9e42";
logging-data="21052"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+KUX6rYjjKliBNDmWQNGEinp1lZZ9N2zk="
User-Agent: G2/1.0
Cancel-Lock: sha1:P3zZBkz2qipSpxbFBNTjfeVFwpg=
View all headers
On Monday, September 14, 2020 at 2:38:49 PM UTC-7, luserdroog wrote:
On Monday, September 14, 2020 at 3:51:24 AM UTC-5, Alexei A. Frounze wrote:
On Sunday, September 13, 2020 at 11:51:13 PM UTC-7, luserdroog wrote:
    // additional flags set by math operators
#define MATHFLAGS *fl |= ( (z&(w?0xffff0000:0xff00))     ?CF:0) \
                       | ( ((z^x)&(z^y)&(w?0x8000:0x80)) ?OF:0) \
                       | ( ((x^y^z)&0x10)                ?AF:0); \
                       SETPF

I don't know where I came up with that expression for OF.
It's gibberish to me now.

It's making sure that the result's sign is the same
as the signs of x and y. If that isn't true, OF gets set.
That works for addition, z = x + y,
but not subtraction, z = x - y.
Unless you exchange things a bit...

add: z = x + y
(z^x)&(z^y)&...

sub: z = x - y
OR, speaking in terms of addition...
sub: x = z + y
(x^z)&(x^y)&...

IOW, for the purposes of OF calculation you need to
exchange x and z in that formula of yours.

Alex

Do I also need to swap x and y if the direction is
reversed and z = y - x?
then y = z + x.
sthg like:
  ((d?x:y)^z)&(x^y)&...

I didn't follow the meaning of "direction" in your code,
but yes, if you're swapping the diminuend and the subtrahend.

That gives you 3 cases:

z=x+y:
(z^x)&(z^y)&...

z=x-y (mathematically equivalent to x=z+y):
(x^z)&(x^y)&...

z=y-x (mathematically equivalent to y=x+z):
(y^x)&(y^z)&...

Putting it all together:

(((is_add||sub_dir)?z:y)^x) &
(((is_add||!sub_dir)?z:x)^y) & ...

Alex



Subject: Re: CMP flags going wrong in my emu?
From: wolfgang kern
Newsgroups: comp.lang.asm.x86
Organization: KESYS-development
Date: Tue, 15 Sep 2020 08:27 UTC
References: 1 2 3 4
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: nowh...@nospicedham.never.at (wolfgang kern)
Newsgroups: comp.lang.asm.x86
Subject: Re: CMP flags going wrong in my emu?
Date: Tue, 15 Sep 2020 10:27:31 +0200
Organization: KESYS-development
Lines: 68
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <rjptve$n0a$1@gioia.aioe.org>
References: <79353012-efc1-4777-aa3d-b31a0df11207o@googlegroups.com>
<f95ea1ca-4332-491d-a706-b24a2dc66fb0o@googlegroups.com>
<6e499cf0-8e55-41f4-b6a5-f0fa91be7fa5o@googlegroups.com>
<6cc81955-fcd7-4cdb-aa73-0a2ce8d3a802o@googlegroups.com>
Reply-To: nowhere@never.at
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: reader02.eternal-september.org; posting-host="06cd29ac3c2e6e689506469e787f9e42";
logging-data="11064"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+6Fwq8i8U4YFkbJvoTNrLVLBFYJCu6AXY="
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.2.2
Cancel-Lock: sha1:mGsVTGrGffcMN0CRYvAAsB/RGbg=
View all headers
On 14.09.2020 19:15, luserdroog wrote:
....
CMP(,R,BX,CX)

3b d9  CMP bx,cx   ;does a faked SUB (bx-cx)
flags affected: CY,PAR,AUX,Z,S,O
usable conditional instructions after this:
Jcc(short or long)/SETcc/CMOVcc/(FCMOVcc is a bit different)

x86 Conditions:
O                            code 70/40/80/90  if OF=0
NO                           code 71 41/81/91  if OF=1
C   aka  B   aka NAE aka <   code 72/42/82/92  if CF=1 if below/if carry
NC  aka  NB  aka AE  aka >=  code 73/43/83/93  if CF=0 if not below/if
above or equal

Z   aka E    aka =           code 74/44/84/94  if ZF=1 if zero/if equal
NZ  aka NE   aka <>          code 75 and so on if ZF=0 if not zero/if
not equal

NA  aka BE   aka <=          code 76           if CF=1 or ZF=1 if not
above/if below or equal

A   aka NBE  aka >  aka NCNZ code 77           if CF=0 and ZF=0 if not
below or equal/if above

S   aka SM   aka -           code 78           if SF=1 (usable after
unsigned cmp/sub/add...)

NS  aka SP   aka +           code 79           if SF=0
P   aka PE                   code 7A           if PE=1 parity even
(works on low byte only)

NP  aka PO                   code 7B           if PE=0 prity odd   ("-")
L   aka NGE  aka <0          code 7C           if SF<>OF if less/if not
greater or equal **

NL  aka GE   aka >=0         code 7D           if SF=OF  if not less/ if
greater or equal **

NG  aka LE   aka <=0         code 7E           if SF<>OF or ZF=1 if less
or equal/if not greater **

G   aka NLE  aka >0          code 7F/4F/9F/9F  if ZF=0 and SF=OF if not
less or equal/if greater **

** this four are made for signed compare...
ie:
  70 xx       JO xx
  0f 80 xx xx JO xxxx
  0f 40/r     CMOVO r
  0f 90/0/rm  SETO r/rm
....
I said this wrong. These are "to" forms, not "from". The first
argument to my CMP macro can be F to create a "from" opcode or blank
(as above) to create a "to" opcode. Elsethread I mentioned the
expanded operator function listed in my codegolf answer, that should
be "addbf" (the "from" form) not "addbt". Sigh. addbf (add byte from)
being opcode 0x00.

Why easy when you can make it complicated ?
what's wrong with the assembler syntax used by NASM,FASM,..(long list)
and also AMD and Intel in their docs ?

sorry if the lines wrap
__
wolfgang



Subject: Re: CMP flags going wrong in my emu?
From: luserdroog
Newsgroups: comp.lang.asm.x86
Organization: A noiseless patient Spider
Date: Tue, 15 Sep 2020 16:12 UTC
References: 1 2 3 4 5
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: luser.dr...@nospicedham.gmail.com (luserdroog)
Newsgroups: comp.lang.asm.x86
Subject: Re: CMP flags going wrong in my emu?
Date: Tue, 15 Sep 2020 09:12:47 -0700 (PDT)
Organization: A noiseless patient Spider
Lines: 34
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <17b6d816-bd4a-41d8-8df4-503499dae137o@googlegroups.com>
References: <79353012-efc1-4777-aa3d-b31a0df11207o@googlegroups.com>
<f95ea1ca-4332-491d-a706-b24a2dc66fb0o@googlegroups.com> <6e499cf0-8e55-41f4-b6a5-f0fa91be7fa5o@googlegroups.com>
<6cc81955-fcd7-4cdb-aa73-0a2ce8d3a802o@googlegroups.com> <rjptve$n0a$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Date: Tue, 15 Sep 2020 16:12:48 +0000
Injection-Info: reader02.eternal-september.org; posting-host="06cd29ac3c2e6e689506469e787f9e42";
logging-data="16030"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX199LbXmiJvP5bOZEDrg2NOXfZYNL98D36E="
User-Agent: G2/1.0
Cancel-Lock: sha1:jvt8ltXaBvAKUk+fTOXUspEIObw=
View all headers
On Tuesday, September 15, 2020 at 3:32:03 AM UTC-5, wolfgang kern wrote:
On 14.09.2020 19:15, luserdroog wrote:

I said this wrong. These are "to" forms, not "from". The first
argument to my CMP macro can be F to create a "from" opcode or blank
(as above) to create a "to" opcode. Elsethread I mentioned the
expanded operator function listed in my codegolf answer, that should
be "addbf" (the "from" form) not "addbt". Sigh. addbf (add byte from)
being opcode 0x00.

Why easy when you can make it complicated ?
what's wrong with the assembler syntax used by NASM,FASM,..(long list)
and also AMD and Intel in their docs ?

sorry if the lines wrap

The whole idea of this project was to build something running on top
of the 8086 emulator. This was to exercise the emulator and shake
out bugs, but also to motivate implementing more opcodes.

For the assembler part, I wanted to put the assembled bytes into a C
data structure. I also wanted complete control over the exact encoding
of the opcodes, mostly so I could make sure it was using codes that
are actually implemented in the emulator.

For these reasons, the best choice I could think of was to make the
assembler with C preprocessor macros that yield a comma separated
list of byte values. One advantage of this approach is that I can
design the *machine code* to be (somewhat) readable. I put opcodes
in hex, M/R/R-M bytes in octal, and offsets in decimal.

"We choose to do these things not because they are easy, but because
they are hard."



Subject: Re: CMP flags going wrong in my emu?
From: olcott
Newsgroups: comp.lang.asm.x86
Organization: A noiseless patient Spider
Date: Wed, 16 Sep 2020 20:06 UTC
References: 1
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: NoO...@nospicedham.NoWhere.com (olcott)
Newsgroups: comp.lang.asm.x86
Subject: Re: CMP flags going wrong in my emu?
Date: Wed, 16 Sep 2020 15:06:56 -0500
Organization: A noiseless patient Spider
Lines: 41
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <WKadneNNvtjC7f_CnZ2dnUU7-RudnZ2d@giganews.com>
References: <79353012-efc1-4777-aa3d-b31a0df11207o@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: reader02.eternal-september.org; posting-host="e78831de870e90a9082da42127b41d4e";
logging-data="15540"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/c789d03CJT+cCmTpU8NCXK4iWK3Tek6k="
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101
Thunderbird/68.12.0
Cancel-Lock: sha1:Q4ggte7dpeaNIzSzVw9TiXCre/g=
View all headers
On 9/13/2020 11:13 PM, luserdroog wrote:
I'm trying to fill out my toy forth interpreter and I think I have
a bug in my emulator for the CMP instruction and therefore probably
also SUB and SBB.

The problem is showing up in my comparator functions
CODE(<,     less,      POP(CX),POP(BX), MOVAXI(0xff,0xff), CMP(,R,BX,CX), JL,2,INC_(R,AX), PUSH(AX))
CODE(>,     more,      POP(CX),POP(BX), MOVAXI(0xff,0xff), CMP(,R,BX,CX), JG,2,INC_(R,AX), PUSH(AX))

When I test it with

WORD(test2a,test2a,    enter, one, ten, less, dot,
                               one, ten, more, dot, ok)

no matter how I permute the arguments -- changing BX and CX in the CMP
instruction, or in the POP order, or in the test script -- the results
never change.

   0 -1 OK

Here's the stack trace on the first one.

ax:ffff cx:000a dx:0000 bx:0001 sp:f000 bp:1ffc si:0e1a di:0000 ip:046d fl:0004 NC NO NS NZ
3b(073) cmpwt: d9(331) x:1 y:10 ->fffffff7
ax:ffff cx:000a dx:0000 bx:0001 sp:f000 bp:1ffc si:0e1a di:0000 ip:046f fl:0891 CA OV SN NZ
7c(174) jl: 02(002) <0>
ax:ffff cx:000a dx:0000 bx:0001 sp:f000 bp:1ffc si:0e1a di:0000 ip:0471 fl:0891 CA OV SN NZ
ff(377) grp2w: c0(300) INC ->0000

The CMP produces fffffff7 which seems like the correct subtraction
extended to 32 bits. But the JL isn't taken.

Are my flags wrong after the cmpwt instruction?


This is a real "emu"
https://i.insider.com/5d31dff836e03c28ef338ee2?width=1300&format=jpeg&auto=webp

--
Copyright 2020 Pete Olcott



1
rocksolid light 0.7.2
clearneti2ptor