Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.lang.asm.x86    |    Ahh, the lost art of x86 assembly    |    4,675 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 4,123 of 4,675    |
|    olcott to wolfgang kern    |
|    Re: Comparing to zero [test]    |
|    30 Aug 20 13:45:50    |
      From: NoOne@NoWhere.com              On 8/28/2020 1:27 AM, wolfgang kern wrote:       > On 28.08.2020 02:48, luserdroog wrote:       >> On Thursday, August 27, 2020 at 3:12:28 PM UTC-5, luserdroog wrote:       >>> Hi everyone,       >>>       >>> I'm working on primitives for my newly working forth interpreter and I'm       >>> having difficulty with comparisons 0= 0> and 0> . These each take a       >>> number from the stack and push 0 or all-bits-1.       >>>       >>> My code for 0= and 0> appear to be producing results, but I get the       >>> wrong       >>> result for 0< even though it seems to follow appropriate parallel logic       >>> as 0>. Any ideas? Does this suggest a bug in assembly or in my emulator?       >>>       >>> CODE(0=, zeroeq, POP(AX),MOVCXI(1,0), CMP(,R,AX,CX),       >>> SBB(,R,AX,AX), PUSH(AX))       >>> CODE(0>, zerogt, POP(AX),MOVCXI(0,0), CMP(,R,AX,CX),       >>> JL,3,MOVCXI(0xff,0xff), PUSH(CX))       >>> CODE(0<, zerolt, POP(AX),MOVCXI(0,0), CMP(,R,AX,CX),       >>> JG,3,MOVCXI(0xff,0xff), PUSH(CX))       >>>       >>> testing:       >>> WORD(run, run, c_lit,0, c_zeroeq, c_dot,       >>> c_lit,12, c_zerogt, c_dot,       >>> c_lit,minus(50), c_zerolt, c_dot,       >>> c_lit,79,c_emit, c_lit,75,c_emit,       >>> c_lit,5,c_double,c_emit, c_bye)       >>>       >>> output:       >>> $ ./a8086       >>> 110OK       >>       >> I changed JL to JLE and JG to JGE. Still not right.       >> Here's a trace through zerogt.       >>       >> ax:01f6 cx:0001 dx:0030 bx:01f8 sp:0ffe bp:2000 si:05ac di:0000       >> ip:01f8 fl:0004 NC NO NS NZ       >> 58(130) popax:       >> ax:000c cx:0001 dx:0030 bx:01f8 sp:1000 bp:2000 si:05ac di:0000       >> ip:01f9 fl:0004 NC NO NS NZ       >> b9(271) movcxi: 00(000) 00(000)       >> ax:000c cx:0000 dx:0030 bx:01f8 sp:1000 bp:2000 si:05ac di:0000       >> ip:01fc fl:0004 NC NO NS NZ       >> 3b(073) cmpwt: c8(310) x:0 y:12 ->fffffff4       >> ax:000c cx:0000 dx:0030 bx:01f8 sp:1000 bp:2000 si:05ac di:0000       >> ip:01fe fl:0891 CA OV SN NZ       >> 7e(176) jle: 03(003) <0>       >> ax:000c cx:0000 dx:0030 bx:01f8 sp:1000 bp:2000 si:05ac di:0000       >> ip:0200 fl:0891 CA OV SN NZ       >> b9(271) movcxi: ff(377) ff(377)       >> ax:000c cx:ffff dx:0030 bx:01f8 sp:1000 bp:2000 si:05ac di:0000       >> ip:0203 fl:0891 CA OV SN NZ       >> 51(121) pushcx:       >> ax:000c cx:ffff dx:0030 bx:01f8 sp:0ffe bp:2000 si:05ac di:0000       >> ip:0204 fl:0891 CA OV SN NZ       >>       >>       >> It should be comparing 0 and 12, so it should take 0-12 and set       >> zf=0 sf=1 and of=1. Then JLE should jump if (sf^of)|zf which is 0.       >> And it seems to be doing all that. Maybe I'm just using CMP wrong?       >>       >> The description from the 8086 family manual:       >>       >> CMP destination,source       >> CMP (Compare) subtracts the source from the destination, which may be       >> bytes or words, but does not return the result. The operands are       >> unchanged, but the flags are updated and can be tested by a subsequent       >> conditional jump instruction. CMP updates AF, CF, OF, PF, SF and ZF.       >> The comparison reflected in the flags is that of the destination to       >> the source. IF a CMP instruction is followed by a JG (jump if greater)       >> instruction, for example, the jump is taken if the destination operand       >> is greater than the source operand.       >>       >> So, in "CMP CX=0,AX=12" CX is the destination. So 0-12. Hmmm.       >> I still don't get it. But all the pieces seem to be here....       >       >       > x86 Conditions:       > O, NO       > C, NC aka B, NB aka <, >=       > Z, NZ aka E, NE aka =, <>       > NA, A aka BE,NBE aka <=,> aka ZorC, aka NCNZ       > S, NS aka -, +       > PE, PO aka P, NP       >       > L, NL aka NGE,GE aka <0,>=0       > NG, G aka LE,NLE aka <=0, >0       >       > only the last four and S/NS work signed       > __       > wolfgang       >              test       --       Copyright 2020 Pete Olcott              --- SoupGate-Win32 v1.05        * Origin: you cannot sedate... all the things you hate (1:229/2)    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca