Skip to content

Holy H*ll – This is Awful

January 28, 2018
;L=max(strlen((char *)str),8);//length to display
	ld2 R12,'O',sp,(12+1) ;reg:INDIRP2(addr)
	Ccall _strlen;CALLU2(ar)*
	cpy2 R11,R15 ;LOADU2*(reg)
	jnU2I R11,8,lbdf,L38 ;LEU2 8 11 L38; LE is flipped test & subtraction
	ld2 R12,'O',sp,(12+1) ;reg:INDIRP2(addr)
	Ccall _strlen;CALLU2(ar)*
	cpy2 R11,R15 ;LOADU2*(reg)
	cpy2 R1,R11 ;LOADU2*(reg)
	lbr L39
L38:
	ldaD R1,8; reg:acon
L39:
	cpy2 R6,R1 ;LOADU2*(reg)

At some point I’ll have to deal with this – callling strlen() twice is an atrocity. It looks like I’m testing to see whether strlen is <8 then either call strlen again or load an 8.

Advertisements

From → Uncategorized

2 Comments
  1. That is a consequence of max being defined as a macro. I see in nstdlib.h:

    #define max(a,b) (((a) > (b)) ? (a) : (b))

    I seemed to remember this problem being mentioned in something I read long ago. A quick check of K&R shows that is where I remember it from. It actually uses a max() macro to illustrate the problem of side effects on page 87.

    The obvious workaround in your case is assign the result from the strlen() call to a variable and then use max() on that.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: