From: Terence on 3 Dec 2007 21:57 OOPS! My point was to emulate how a human solves SUDOKU puzzles WITHOUT using exhaustive searches. May Herbert's isn't that kind. I took Heebert's batch file code and cut-and-pasted to Notepad, saved as a batch file and then ran the batch file to make sudo.com This does some funny things at 100H which don't look right at all. Anyway, I ran this with the a1 problem as-is, using sudo a1 <ret>. .. It wouldn't terminate and hung up on "illegal instruction" ..C5:057b IP:058c OP:63 3f 48 3f Any clues? Then I tried dis-assembly of the created program: this can't be correct surely? .. code SEGMENT ASSUME CS:code, DS:code ORG 100h start: INC DX PUSH 40h PUSH 7Ah PUSH 3060h POP AX SUB AX,2F60h PUSH AX PUSH AX PUSH AX PUSH AX PUSH AX PUSH AX POPA SUB [SI+45h],AL SUB [SI+4Dh],AL SUB [SI+4Fh],AL SUB [SI+68h],AL SUB [SI+73h],CL SUB [SI+75h],CL
From: Evenbit on 3 Dec 2007 21:59 On Dec 3, 8:47 am, Frank Kotler <fbkot...(a)verizon.net> wrote: > > In an example of "how to call C", it really ought to be there, I think. > Printf is wasted on hello world, anyway. Now *floats* are a bit of a > PITA to display, and might be worth compromising our principles for. > Printf thinks all floats are double precision, and take 8 bytes on the > stack. If you've got the thing in an FPU reg, "sub esp, 8","fst qword > [esp]"... Interesting.... extern _printf extern _exit global _main section .data fmt db "Your holiday desert is %f percent of pie.", 10, 0 section .text _main: finit fldpi sub esp, 8 fst qword [esp] push fmt call _printf add esp, 3 * 4 push dword 0 call _exit > ; nasm -f elf32 floatnum.asm > ; ld -o floatnum floatnum.o -I/lib/ld-linux.so.2 -lc > > extern printf > global _start > > section .data > fmt db "The number is: %f", 10, 0 > num dq 1.234 > > section .text > _start: > push dword [num + 4] > push dword [num] > push fmt > call printf > add esp, 3 * 4 > > mov eax, 1 > int 80h Yes, a few extra examples sprinkled on top of the PGU group makes a nice beginner collection. Maybe I'll get some ideas from the HLA examples or the "12 Lessons" to flesh it out some. Nathan.
From: Rosario on 4 Dec 2007 02:19 In data Mon, 3 Dec 2007 18:57:03 -0800 (PST), Terence scrisse: >OOPS! >My point was to emulate how a human solves SUDOKU puzzles WITHOUT >using >exhaustive searches. >May Herbert's isn't that kind. > >I took Heebert's batch file code and cut-and-pasted to Notepad, saved >as a batch file and then ran the batch file to make sudo.com > >This does some funny things at 100H which don't look right at all. >Anyway, I ran this with the a1 problem as-is, using >sudo a1 <ret>. >. >It wouldn't terminate and hung up on "illegal instruction" >.C5:057b IP:058c OP:63 3f 48 3f >Any clues? i have pasted *all* code and exercise in notepad change the name of the file in "h.bat" run h.bat in a dos windows, no .com file but all goes ok for the run (not know how) but how to play in that game? what are the rules?
From: Herbert Kleebauer on 4 Dec 2007 02:42 Terence wrote: > I took Herebert's batch file code and cut-and-pasted to Notepad, saved > as a batch file and then ran the batch file to make sudo.com > Then I ran this with the a1 problem as-is. > . > It wouldn't terminate and hung up on "illegal instruction" > .C5:057b IP:058c OP:63 3f 48 3f > Any clues? Most probably this is a copy and paste error (some editors have a problem with ` followed by a character). Better don't copy and paste but save the posting and then open it with an editor (or assembly the source yourself, then you get the real binary and not an ascii encoded one). Here a different ascii version without the ` character. ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: @echo off echo hD1X-s0P_kUHP0UxGWX4ax1y1ieimnfeinklddmemkjanmndnadmndnpbbn>sudo.com echo hhpbbnpljhoxolnhaigidpllnbkdnhlkfhlflefblffahfUebdfahhfkokh>>sudo.com echo wPajQJ///MKiF0///M5uqA///k1AmNDRFkH1r0jNl7hNDgekbNKWKgC1bNq>>sudo.com echo l5///yDUN2OA0b8CpaVyX1///aVCK0///axUUj0///M5uq1///ErLat(a)L4/>>sudo.com echo //aZPI////bNqW5I7kplXN0XC3adf/////apP1////aJ7ooVVNcX4///kNa>>sudo.com echo Zc4aVyS////oFXNcP4///UNF(a)iNBJ6ra4AsEQaN8OUN2OA0b8ShaV@B4///>>sudo.com echo fnVNsOE0//kuCM5iqH///gC2aV(a)54///aVyz0///aVCL1///aVib1///a0a>>sudo.com echo NymJ0//UNz1e0//kuCM5Mat(a)c5///ax(a)L4///aZPI////nTaNZOKMEOqka0>>sudo.com echo aNymJ0//UNt54///UNlwzNahc041QRPNqUD6UN0XC3adf/////a4nqapP1/>>sudo.com echo ///aJ7ooBmNaZc4aViJ////nZUN2ywza42ofvUN4iRR4MKWHjC0aBsmzPKo>>sudo.com echo WPKHp4hN4iBRbUb0bNKWSgC1a4AsEQaN8OUN2OA0b8iZaJszax/WxxzzzPK>>sudo.com echo MEWjN2PqU76UNV0NyaBgNUNajQJ///MKi8////Mqi7////QaN(a)OUN89wNaB>>sudo.com echo /0SSaN(a)EVbahIRmbXkaxEVt2///MKke2VN8/RDyDUNDI7u////aBclYQas3>>sudo.com echo PajQJ///MKi8////Mqi7////QaN(a)OUN89wNap7@PRaNBmKP/QaN2EUfbNq1>>sudo.com echo IseN(a)Jrtt7gNDIcd////a4guEMK1ErXz2Mq24K8///UN2OA0b8Siat(a)L4//>>sudo.com echo /aZv/////ahv/////bNqW5MKW1TaN2M30bNq1KFkNaBUF7QaN(a)M41bNq/5F>>sudo.com echo mNahUJYQaN2M39bNq1KVmNaBUFgQaN(a)M4@bNq/5VoNahUJ7RaN2M3HbNq1K>>sudo.com echo loNaBUFERaN(a)M4It7QRVMKke2VN8/RDyDERJMqU5nUN(a)JLYaBcl7Ras3OKM>>sudo.com echo EWjN2PKMEajN2P5MkqUNcf7////g9M5u11///MajQJ///Mqi8////MKj8//>>sudo.com echo //QaN(a)OVN2OA0aZf1////k1XNFfiQ6M5Eb8ixkuWNcv3///UNBJbqkqUNc@>>sudo.com echo 3////g9M5uu////MqGp0gNV0dN2P5MaZclbl9V/H61aVC7////f(a)jNV0dN2>>sudo.com echo P5MoyXiMJEi0/EAPrQ7a45YaxUh5UJ0aBgNU89K4E(a)EuWJ0t5//v5//B6WN>>sudo.com echo V0dN2X@/ApQ7BcEOglKNb45PUYaPkJ6R/oU1YZaQZB5RgZ67nx5PqJ5N/oU>>sudo.com echo 1nx5PqJ5NUQLOoV57jtKNU7LNXJbQnZqPi0E29sqPo0mQjlaRZ4aMgJ57rZ>>sudo.com echo 5Rc0mPiJ57mJqMp8rQdxaP//UP.>>sudo.com :::::::::::::::::::::::::: puzzle 1 echo 000 000 501 >a1 echo 000 040 060 >>a1 echo 620 300 000 >>a1 echo 001 702 000 >>a1 echo 000 406 083 >>a1 echo 007 000 000 >>a1 echo 083 000 009 >>a1 echo 700 050 400 >>a1 echo 000 900 100 >>a1 :::::::::::::::::::::::::: puzzle 2 echo 000 060 080 >a2 echo 700 500 000 >>a2 echo 000 801 000 >>a2 echo 009 006 000 >>a2 echo 000 000 201 >>a2 echo 000 024 600 >>a2 echo 030 000 052 >>a2 echo 105 003 000 >>a2 echo 020 900 408 >>a2 :::::::::::::::::::::::::: puzzle 3 echo 060 700 080 >a3 echo 040 050 900 >>a3 echo 000 001 003 >>a3 echo 002 000 001 >>a3 echo 070 004 060 >>a3 echo 800 003 500 >>a3 echo 900 800 000 >>a3 echo 001 020 070 >>a3 echo 050 006 000 >>a3 :::::::::::::::::::::::::: puzzle 4 echo 070 080 050 >a4 echo 900 000 002 >>a4 echo 000 405 000 >>a4 echo 006 040 700 >>a4 echo 300 702 004 >>a4 echo 000 050 900 >>a4 echo 004 803 000 >>a4 echo 700 000 009 >>a4 echo 030 090 010 >>a4 :::::::::::::::::::::::::: puzzle 5 echo 000 005 009 >a5 echo 001 000 300 >>a5 echo 040 902 010 >>a5 echo 506 030 007 >>a5 echo 000 020 000 >>a5 echo 003 000 408 >>a5 echo 090 500 020 >>a5 echo 007 000 900 >>a5 echo 000 008 000 >>a5 :::::::::::::::::::::::::: puzzle 6 (an easy one) echo 400 000 582 >a6 echo 000 503 000 >>a6 echo 700 028 090 >>a6 echo 897 000 050 >>a6 echo 304 090 108 >>a6 echo 060 000 937 >>a6 echo 070 630 005 >>a6 echo 000 807 000 >>a6 echo 238 000 001 >>a6 :::::::::::::::::::::::::: puzzle 7 echo 000 000 002 >a7 echo 009 700 100 >>a7 echo 050 301 040 >>a7 echo 023 000 650 >>a7 echo 000 000 000 >>a7 echo 046 000 790 >>a7 echo 000 507 000 >>a7 echo 002 600 300 >>a7 echo 800 000 001 >>a7 :::::::::::::::::::::::::: puzzle 8 echo 300 070 005 >a8 echo 070 009 000 >>a8 echo 400 005 020 >>a8 echo 701 060 008 >>a8 echo 008 000 300 >>a8 echo 090 000 700 >>a8 echo 020 700 009 >>a8 echo 050 800 040 >>a8 echo 000 010 000 >>a8 sudo <a1 pause sudo <a2 pause sudo <a3 pause sudo <a4 pause sudo <a5 pause sudo <a6 pause sudo <a7 pause sudo <a8 pause for %%i in (a1 a2 a3 a4 a5 a6 a7 a8 sudo.com) do del %%i ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: The source code: @=$100 bclr.w #10,sr ;*********************************************************************** ; read 81 digits from stdin, anything else is ignored, 0 for unknown ;*********************************************************************** move.l #brett,r5 move.l #81,r2 _10: bsr.l getc sub.b #'0',r0 blo.b _10 beq.b _20 cmp.b #9,r0 bhi.b _10 eor.l r1,r1 bset.l r0,r1 move.l r1,(r5) br.b _30 _20: move.l #$03fe0000,(r5) _30: addq.l #4,r5 dbf.l r2,_10 ;*********************************************************************** bsr.l display bsr.l check bcs.l _err bsr.l reduce beq.b _found0 ;*********************************************************************** ; if not found directly, do one level of recursion of try and error ;*********************************************************************** move.l #brett,r5 move.l #81,r2 _50: move.l (r5),r0 tst.w r0,r0 bne.b _40 lsr.l #16,r0 move.l #2,r1 move.l #9,r4 _60: tst.l r1,r0 beq.b _70 bsr.l save move.l r1,(r5) bsr.l reduce beq.b _found1 bsr.l restore _70: lsl.l #1,r1 dec.l r4 bne.b _60 _80: lsl.l #16,r0 move.l r0,(r5) _40: addq.l #4,r5 dbf.l r2,_50 move.l #text4,r0 br.b _130 _found0:move.l #text2,r0 br.b _120 _err: move.l #text1,r0 br.b _130 _found1:move.l #text3,r0 _120: bsr.l display _130: bsr.l out_text bsr.l exit ;*********************************************************************** save: movem.l r0-r7,-(sp) move.l #brett,r5 move.l #brett1,r6 br.b rest1 restore:movem.l r0-r7,-(sp) move.l #brett1,r5 move.l #brett,r6 rest1: move.l #81,r2 rep_r2 move.l (r5)+-,(r6)+-{s1} movem.l (sp)+,r0-r7 rts.l ;*********************************************************************** ; remove all impossible configurations ; carry: 1: unsolveabel ; 0: solveabel ; zero: 1: solved ; 0: not solved ;*********************************************************************** reduce: movem.l r0-r7,-(sp) _90: move.l #brett,r5 move.l #81,r2 eor.l r6,r6 _50: move.l (r5),r0 tst.w r0,r0 bne.b _40 orq.l #1,r6 lsr.l #16,r0 move.l #2,r1 eor.l r3,r3 move.l #9,r4 _20: tst.l r1,r0 beq.b _10 move.l r1,(r5) bsr.l check bcc.b _70 orq.l #-1,r6 eor.l r1,r0 br.b _10 _70: tst.l r3,r3 bne.b _30 move.l r1,r3 br.b _10 _30: orq.l #-1,r3 _10: lsl.l #1,r1 dec.l r4 bne.b _20 tst.l r3,r3 beq.b _err bmi.b _80 move.l r3,(r5) br.b _40 _80: lsl.l #16,r0 move.l r0,(r5) _40: addq.l #4,r5 dbf.l r2,_50 tst.l r6,r6 bmi.l _90 movem.l (sp)+,r0-r7 bclr.w #0,sr ; carry=0 zero=1(solution found) or 0 rts.l _err: orq.l #1,r0 ; clear zero flag movem.l (sp)+,r0-r7 bset.w #0,sr rts.l ;*********************************************************************** ; check if legal ; carry: 0: legal ; 1: illegal ;*********************************************************************** check: movem.l r0-r7,-(sp) move.l #brett,r5 move.l #9,r2 _40: move.l #8,r3 move.l (r5),r0 move.l r0,r1 _30: add.l (r5,r3*4),r0 or.l (r5,r3*4),r1 dec.l r3 bne.b _30 cmp.w r0,r1 bne.l _err lsr.l #16,r1 or.l r1,r0 cmp.w #$03fe,r0 bne.l _err addq.l #9*4,r5 dbf.l r2,_40 move.l #brett,r5 move.l #9,r2 _60: move.l #8,r3 move.l (r5),r0 move.l r0,r1 _50: lea.l (r3,r3*2),r4 lea.l (r4,r4*2),r4 add.l (r5,r4*4),r0 or.l (r5,r4*4),r1 dec.l r3 bne.b _50 cmp.w r0,r1 bne.l _err lsr.l #16,r1 or.l r1,r0 cmp.w #$03fe,r0 bne.l _err addq.l #4,r5 dbf.l r2,_60 move.l #brett,r5 move.l #3,r2 _20: move.l #3,r3 _10: move.l (r5),r0 move.l r0,r1 add.l 0*36+1*4.b(r5),r0 or.l 0*36+1*4.b(r5),r1 add.l 0*36+2*4.b(r5),r0 or.l 0*36+2*4.b(r5),r1 add.l 1*36+0*4.b(r5),r0 or.l 1*36+0*4.b(r5),r1 add.l 1*36+1*4.b(r5),r0 or.l 1*36+1*4.b(r5),r1 add.l 1*36+2*4.b(r5),r0 or.l 1*36+2*4.b(r5),r1 add.l 2*36+0*4.b(r5),r0 or.l 2*36+0*4.b(r5),r1 add.l 2*36+1*4.b(r5),r0 or.l 2*36+1*4.b(r5),r1 add.l 2*36+2*4.b(r5),r0 or.l 2*36+2*4.b(r5),r1 cmp.w r0,r1 bne.b _err lsr.l #16,r1 or.l r1,r0 cmp.w #$03fe,r0 bne.b _err addq.l #3*4,r5 dec.l r3 bne.b _10 addq.l #2*9*4,r5 dbf.l r2,_20 movem.l (sp)+,r0-r7 bclr.w #0,sr rts.l _err: movem.l (sp)+,r0-r7 bset.w #0,sr rts.l ;*********************************************************************** display:movem.l r0-r7,-(sp) move.b #13,r0 bsr.l putc move.b #10,r0 bsr.l putc move.l #brett,r5 move.l #9,r3 _40: move.l #9,r4 _30: move.l (r5),r1 addq.l #4,r5 move.l #10,r2 move.b #'0',r0 _20: lsr.l #1,r1 bcs.b _10 inc.l r0 dbf.l r2,_20 move.b #'.',r0 _10: bsr.l putc dec.l r4 bne.b _30 move.b #13,r0 bsr.l putc move.b #10,r0 bsr.l putc dec.l r3 bne.b _40 movem.l (sp)+,r0-r7 rts.l ;*********************************************************************** out_text: movem.l r0-r7,-(sp) move.l r0,r5 _20: move.b (r5)+-,r0 tst.b r0,r0 beq.b _10 bsr.l putc br.b _20 _10: movem.l (sp)+,r0-r7 rts.l ;*********************************************************************** ;*************** start OS dependent functions ************************** ;*********************************************************************** getc: movem.l r0-r7,-(sp) move.b #$3f,m0 move.w #buf,r1 move.w #1,r2 eor.w r3,r3 trap #$21 movem.l (sp)+,r0-r7 movu.bl buf,r0 rts.l putc: movem.l r0-r7,-(sp) move.b r0,buf move.b #$40,m0 move.w #buf,r1 move.w #1,r2 move.w #1,r3 trap #$21 movem.l (sp)+,r0-r7 rts.l exit: move.w #$4c00,r0 trap #$21 ;*********************************************************************** ;***************** end OS dependent functions ************************** ;*********************************************************************** text1: dc.b 13,10,"illegal input",0 text2: dc.b 13,10,"directly solved",0 text3: dc.b 13,10,"solved with one recursion",0 text4: dc.b 13,10,"not solveable with one recursion",0 even 4 buf: blk.l 1 brett: blk.l 9*9 brett1: blk.l 9*9
From: Herbert Kleebauer on 4 Dec 2007 02:49
Terence wrote: > > Herbert, better still here are even some I coudn't solve anyway. > > 007000800050020090903000701000408000030000060000705000409000300020080070001000400 > 200030056007010000001600003840000000002000500000000061500003900000040700370090005 > 040000065009020300005100000000500030000639000010008090004006700008040100350000040 > 009700001704800000500060070000300060020000010030009000090030002000008504800001600 > 020000900400506710300000000003085000000174000000390600000000008085901007006000040 > 810000200000007800007000014400090008006050900200070001570000300003400000009000026 > 593006001010050006000700000050000400070804050002000090000008000700030060600100732 > 000109000006040900800000005070050080215000739030010020700000003001070200000804000 > 039007000000500201000090070960000000407000503000000019090020000503008000000400120 > 700605009000800030001000004007000205090000080308000700200000600010009000800506007 > 500200010001900730000000800050020008062039000000004300000000000080467900007300000 > 000023000004000100050084090001070902093006000000010760000000000800000004060000587 > 000042059450090008000000000000004080000000703000836002369200001700000000005001600 > 000000000360000920000010070000000204000036500100025730072809300900000080040000000 > 600400030000001050410800000040350200000700008002060500900000000730500086004000700 > 000300805060000030000050267006100002003405700004008000278000900000001000000000600 > 040080700020000000800030510000208906000009020000500000100000300090406005000050000 > 005100000600003000300000706000030601009050400802090000401000005000500008000007200 > 200000007015000020080200006000000064890000000000050910040815000061030000000006400 Saved it as a.txt and the following solved them all: for /f %%i in (a.txt) do ( echo %%i|sudo.com pause) |