Assembly

Página 1/5
| 2 | 3 | 4 | 5

Por rolandve

Master (218)

Imagen del rolandve

28-04-2020, 17:56

Looking at Pascal and C, I also know that the real speed comes from assembly. I puzzled a small routine that writes a value X times to memory ( a kind of fill routine). Turbo Pascal is kind enough to substitute variable for their values when using inline. The issue I have is with the jump routine. How do I indicate in turbopascal inline that it should jump to a label, whose location I don't know. In the code below, if B is not zero, we need to jump back to increment HL and decr B again, etc.

Any suggestions are welcome!

{ (byte)rep : the number of repeats }
{ (byte)cr : the value to be written }
{ (int)addr : the start address }
Inline (

$3a/rep  		{  ld a, (rep)}
$47/        		{  ld b,a }
$3a/char/  	{  ld a,(cr) }
$2A/addr/  	{ ld HL,addr}
$77/   		{ ld (HL),A
$23/  		{ inc HL)
$5/            	{ dec b }
$C2/         	{ jp nz,wri }
C9   	     		{ ret )
);

Login sesión o register para postear comentarios

Por Dolphin101546015

Champion (268)

Imagen del Dolphin101546015

28-04-2020, 18:04

Use relative jump

Por sd_snatcher

Prophet (3270)

Imagen del sd_snatcher

28-04-2020, 18:31

In this case it's even better to use DJNZ, instead of DEC B ; JR NZ.

Por rolandve

Master (218)

Imagen del rolandve

28-04-2020, 19:11

So I end up with the code below. When used in TP it compiles great.The jump goes in a right direction, b decreases and the prompt return. However, no data is written. mem[addr] reveals no values. So my guess is that the construct: ld (hl),a ($77) is wrong or ld a,(**) $3a/ch does not work. Any tips? Thanks

Inline (

$3a/rep/  	{  ld a, (rep)}
$47/        		{  ld b,a }
$3a/ch/  		{  ld a,(ch) }
$2A/addr/  	{ ld HL,addr}
$77/   		{ ld (HL),a}
$23/  		{ inc HL) }
$5/            	{ dec b  } 
$20/-3        	{ jr nz,wri }
C9   	     		{ ret )
);

Por rolandve

Master (218)

Imagen del rolandve

28-04-2020, 19:12

sd_snatcher wrote:

In this case it's even better to use DJNZ, instead of DEC B ; JR NZ.

I just found that. First I try to get this code running. It doesn't do what I expect. At least it terminates nicely without hang.

Por zeilemaker54

Champion (275)

Imagen del zeilemaker54

28-04-2020, 19:25

-3 should be -5

Por rolandve

Master (218)

Imagen del rolandve

28-04-2020, 19:56

jr nz is two bytes, aha. That makes sense. There however is reason I see no values. Turbo Pascal can't handle values bigger the 32766 (signed ints). So the address I got from TP was 23... Byte #23 in memory is certainly not empty.

working around it to see if the code actually works or not I choose and address that should be safe $7c00, yet the memory is not written.... I would expect something, I try to write 65 to this address.

procedure aFill;

Var
	rep : byte;
	ch : byte;
	test : string[10];
	ad : real;
	lus : integer;

begin;
	rep:=10;
	ch:=65;
	ad:=$7C00;
	inline($3a/rep/$47/$3a/ch/$2a/ad/$77/$23/$5/$20/-5/$C9);
	for lus:=$7c00 to $7c00 + 10 do
		writeln(mem[lus]);
end;

Begin;
	aFill;
end.


Por Daemos

Paragon (1718)

Imagen del Daemos

28-04-2020, 21:41

IF you like to write safe into RAM start somewhere @ hex C000 that address is rarely used for mem writing. It also comes with the added bonus that it will always be set to RAM. No guarantees at addresses below $C000

You like to write something to memory. try this little snippet

ld a,1 ;just a simple value could be anything
ld hl,$C000 ;set pointer to address
ld (hl),a ;write value to pointer you now have something in RAM

Now if you want to loop this little snippet of code do something like

label:

ld b,400 ;write 400 times

ld a,1
ld hl,$C000
ld (hl),a

inc hl ;next part of RAM 

djnz label

Por ARTRAG

Enlighted (6361)

Imagen del ARTRAG

28-04-2020, 22:24

Beware the label position
It should be just before ld (hl),a

Por Daemos

Paragon (1718)

Imagen del Daemos

28-04-2020, 23:33

Yes indeed. Otherwise eternal loop.

Por Manel46

Hero (554)

Imagen del Manel46

28-04-2020, 23:38

And b is an 8-bit register.

Página 1/5
| 2 | 3 | 4 | 5