From: io_x on

"io_x" <a(a)b.c.invalid> ha scritto nel messaggio
news:4acaf615$0$830$4fafbaef(a)reader5.news.tin.it...
> ; *******************************************
> ; *** Fa il labirinto
> ; *******************************************
> ; suppone all'ingresso che cx==0
xor cx, cx ; +2?
> ; parte dalla casella puntata da si
> inc si ; punta all'interno della casella, dove c'e'
> 'N'
> .4: mov word[si], " " ; " " significa visitata
> .5: mov cl, 4
> call ran ; le caselle confinanti sono 4
> .6: and dx, 03h ; dl=0[destra],1[basso],2[sinistra],3[alto]
> mov di, dx
> mov bp, dx
> mov bx, [muro+di+bp] ; in bx offset del muro
> not di
> and di, 1
> mov bp, bx
> add bp, bx ; se bp=2*bx-(not(di)&1)
> sub bp, di ; => in bp offset della prossima casella
> cmp byte[si+bp], 'N'
> je .a ; se tale casella non e' visitata va in .a
> .7: inc dx
> loop .6 ; vai alla prossima casella
> ; ** caso le caselle sono tutte visitate
> cmp sp, 0FFFEh
> jae .z
> ; se lo stack e' vuoto esci[ e'in casella iniziale]
> pop dx
> pop si ; altrimenti prende la casella precedente
> mov cl, 4
> jmp short .7
> %if BytesMemory>24000
> .e: mov sp, 0FFFEh
> ret ; nel caso di errore non stampa proprio niente:
> ; ritorna al DOS
> %endif
> .a: ; ** caso vi � una casella non visitata
> ; leva il muro di divisione [ed eventualemente una N]
> mov word[si+bx], " "
> ; che verra' in ogni caso levata dall'istruzione in .4
> %if BytesMemory>24000
> cmp sp, limite
> jbe .e ; lo stack non puo' invadere questo file in memoria
> %endif
> push si
> push dx
> add si, bp
> jmp short .4
> .z:
> ; ******************************
> ; *** Stampa sullo schermo
> ; ******************************
> lea dx, [arr+sopra2]
> mov ah, 09h
> int 21h ; usa si per stampare l'array
> ret


From: Esra Sdrawkcab on
On Tue, 06 Oct 2009 08:54:24 +0100, io_x <a(a)b.c.invalid> wrote:

>
> "Benjamin David Lunt" <zfysz(a)frontiernet.net> ha scritto nel messaggio
> news:%2oym.93874$u76.41064(a)newsfe10.iad...
>>
>> "io_x" <a(a)b.c.invalid> wrote in message
>> news:4ac9886b$0$828$4fafbaef(a)reader5.news.tin.it...
>>>
>>>> example n > x.txt
>>>> entry n > e.txt
>>>> fc e.txt x.txt
>>>> where n is a number from 0 to 100
>>>
>>> Are you saying that the program "entry n" has to be the same output
>>> of the "example n" for n from 0 to 100 ?
>>>
>>> but where it is written in the rules??
>>
>> Sorry. The rules may not specifically say that. We have
>> been doing this for many years, and it has just been a
>> given. Each compo much pass a test suite of some kind.
>> We have always had a test suite.
>>
>> Also, we have had many discussion about the current and
>> previous compos on the forum and email list. Again,
>> sorry about that, but we usually don't get many new entrants.
>>
>> However, I would bet that if you change your code to produce
>> the same random number as the example, it will pass the test.
>
> what to change for to past test0.bat?
> change the random number generator, the association cell numbers 0..4,
> the function that calculate from the wall the position,
> and push/pop the current cell number (it should be 204 byte)


It passes!


A few simple savings given below

> %define L 25
> %define H 10
>

you don't need to worry that sp overflows, the mazes are all fixed and you
don't need to cater for large L and H

where you use LEA reg, [address]
use Mov reg, address
saves 1 byte each time
can mov cl,limit (limit<256) rather than mov cx,limit if ch=0 from
previous use.
saves 1

> ;%define L 97
> ;%define H 97
>
> ;%define L 10
> ;%define H 749
>
> %define BytesMemory ((L+1)*(H+2)*6)
> %define H21 (2*H+1)
>
> %define sopra (L+1)*6
> %define sopra2 (L+1)*3
>
> %define LineareMax 3*((L-1)+2*(L+1)*H)+1
> %define passi (LineareMax-sopra-1)/3
>
> org 100h
> Start:
> ; ****************************
> ; *** Prende il numero with the help by Esra Sdrawkcab
> ; ****************************

In the Rules it says we can't assume a cr at end of commandline, but in
General it does!


> ; assumo che ax==0
> mov si, 081h
> mov bl, ' '
> .0: aad 10 ; al+=10*ah e ah=0
> mov ah, al
> lodsb
> sub al, bl
> mov bl, '0' ; prima ' ' poi '0'
> jge .0 ; o un char minore di '0'
> mov [seed], ah ; inizializza il seed per rand
> ; *******************************************
> ; *** Fa la griglia
> ; *******************************************
> mov di, arr
> mov cx, BytesMemory
> mov al, 10
> lea si, [di+sopra]
this isn't needed until later, and can be a direct address, i.e .
mov si, arr+sopra


> rep stosb ; tutto 10 [visitato] qui cx=0
> lea di, [si-sopra2]
lea -> mov
this amount can be calculated at assembly time:
mov di, arr+sopra2, I think

> mov bx, H21
can we assume bh=0? I think so
mov bl,H21

> mov ax, "+-"
> mov dx, "|N" ; le caselle NN: non visitate
> .2: mov cx, L ; altrimenti visitate
as cx was 0 from above, you need only mov cl,L
> .3: stosw
> mov byte[di], ah
> inc di
> loop .3
> stosb
> mov byte[di], 0Dh
> inc di
> inc di ; fa la linea
> xchg ax, dx
> dec bx
> jnz .2 ; passa alla linea successiva
> mov byte[di], '$'
> mov byte[di-sopra2-3], 07fh
can be a direct memory address

> mov byte[si], 02h ; ritorna in si la casella iniziale
> ; **************************************
> ; *** Trova una casella casuale
> ; **************************************
> ; P(x,y)=i_inz+y*(L+1)*6+x*3
> mov cx, L
again cl rather than cx
> call ran
> mov di, dx
> add di, dx
> add di, dx ; x*3
> mov cx, H
cl not cx
> call ran
> mov ax, sopra
> mul dx ; y*(L+1)*6
> add ax, di
> add si, ax ; in si la casella iniziale del labirinto
> ; *******************************************
> ; *** Fa il labirinto
> ; *******************************************
> ; suppone all'ingresso che cx==0
> ; parte dalla casella puntata da si
> inc si ; punta all'interno della casella, dove
> c'e' 'N'
> .4: mov word[si], " " ; " " significa visitata
> .5: mov cl, 4
> call ran ; le caselle confinanti sono 4
> .6: and dx, 03h ;
> dl=0[destra],1[basso],2[sinistra],3[alto]
> mov di, dx
> mov bp, dx
> mov bx, [muro+di+bp] ; in bx offset del muro
> not di
> and di, 1
> mov bp, bx
> add bp, bx ; se bp=2*bx-(not(di)&1)
> sub bp, di ; => in bp offset della prossima casella
> cmp byte[si+bp], 'N'
> je .a ; se tale casella non e' visitata va in
> .a
> .7: inc dx
> loop .6 ; vai alla prossima casella
> ; ** caso le caselle sono tutte visitate
> cmp sp, 0FFFEh
> jae .z

is there no tidier way to exit?

> ; se lo stack e' vuoto esci[ e'in casella iniziale]
> pop dx
> pop si ; altrimenti prende la casella precedente
> mov cl, 4
> jmp short .7

> %if BytesMemory>24000
> .e: mov sp, 0FFFEh
> ret ; nel caso di errore non stampa proprio
> niente:
> ; ritorna al DOS
> %endif

%if.. %endif can be removed

> .a: ; ** caso vi � una casella non visitata
> ; leva il muro di divisione [ed eventualemente una N]
> mov word[si+bx], " "
> ; che verra' in ogni caso levata dall'istruzione in
> .4
> %if BytesMemory>24000
> cmp sp, limite
> jbe .e ; lo stack non puo' invadere questo file in
> memoria
> %endif

%if.. %endif can be removed

> push si
> push dx
> add si, bp
> jmp short .4
> .z:
> ; ******************************
> ; *** Stampa sullo schermo
> ; ******************************
> lea dx, [arr+sopra2]
mov
> mov ah, 09h
> int 21h ; usa si per stampare l'array
> ret
>
> ; ritorna un numero 0..cx in dx
> ran:
> mov ax, 04e35h
> imul word[seed]
> inc ax
> mov [seed], ax
> shr ax, 8
> xor dx, dx
> idiv cx
> ret
>
> align 2

is there a need to align?
> seed dw 0

> ;;
> ; +--+--+--+
> ; | |3 | |
> ; +--+--+--+
> ; | 2|NN|0 |
> ; +--+--+--+
> ; | |1 | |
> ; +--+--+--+
> ; dl=0[destra],1[basso],2[sinistra],3[alto]
> ;;
>
> ; 0 1 2 3
> muro dw 2, sopra2, -1, -sopra2
>
> Section .bss
> arr resb BytesMemory
> fine resb 512 ; for to be sure
> limite resb 4
>
>
>
>


--
Nuns! Reverse!
From: Esra Sdrawkcab on
On Tue, 06 Oct 2009 22:14:40 +0100, Esra Sdrawkcab <admin(a)127.0.0.1> wrote:


>
> where you use LEA reg, [address]
> use Mov reg, address
> saves 1 byte each time


I think this maybe a tiny bit of a lie.
Sorry.

--
Nuns! Reverse!
From: Benjamin David Lunt on

"Esra Sdrawkcab" <admin(a)127.0.0.1> wrote in message
news:op.u1edaqyxhswpfo(a)dell3100...
> On Tue, 06 Oct 2009 08:54:24 +0100, io_x <a(a)b.c.invalid> wrote:
>
>
> It passes!
>
>

Yep, it does. I have added it to the list at
http://www.frontiernet.net/~fys/hugi/hcompo.htm

Thanks,
Ben


From: io_x on

"Esra Sdrawkcab" <admin(a)127.0.0.1> ha scritto nel messaggio
news:op.u1edaqyxhswpfo(a)dell3100...
> On Tue, 06 Oct 2009 08:54:24 +0100, io_x <a(a)b.c.invalid> wrote:
>> ; ****************************
>> ; *** Prende il numero with the help by Esra Sdrawkcab
>> ; ****************************
>
> In the Rules it says we can't assume a cr at end of commandline, but in
> General it does!

the below code assume that in 081h there is one
0dh (if the program has no argument)
or one space ' ' (if the program has some argument
and this is trust by the rules)
(it seems in the example.com there is some near to it)

if there is some arg, begin to read 082h
it end when find ' ' or 0dh
if that is the number < 255 it gets it right
if it is some other (eg. "entry w123") is UB

>
>> ; assumo che ax==0
>> mov si, 081h
>> mov bl, ' '
>> .0: aad 10 ; al+=10*ah e ah=0
>> mov ah, al
>> lodsb
>> sub al, bl
>> mov bl, '0' ; prima ' ' poi '0'
>> jge .0 ; o un char minore di '0'
>> mov [seed], ah ; inizializza il seed per rand