The Channel logo

* Posts by liar

2 posts • joined Tuesday 4th December 2007 13:49 GMT

Posted in Bloody code!
liar

@Chris W

(Not that I was the one who made the original challenge, and not that portability was the point, but let's see if I can answer this).

Firstly I would say that if you are trying to port assembler from one instruction set to another then you should almost certainly be starting again from scratch. My comments on portability were aimed more at moving from one family member to another within an instruction set. A few years ago there was a trend for increasing pipe-line lengths and code that did this kind of thing tended to get caught out. Too clever for it's own good.

However to answer your contention I am not aware of any main-stream processors which don't have the ability to load from an address specified in a register. Assuming you can do this then you just have to load the register with the base address then add the offset, then load.

ie (in pseudo assembler)

Mov r1,x

Add r1,W

Ldr r2 from r1

Can you think of a sensible processor which is not able to do this?

To be honest if you are coding in assembler then I think most programmers would agree that a different set of rules should apply from those used in a higher level language. In C you can always manage a look-up table with arrays, and let the compiler find the best way to do it.

Nowadays even in embedded applications you should only rarely be venturing into assembler, and usually only then for horribly speed or space constricted bits of code.

Posted in Bloody code!
liar
Stop

@Chris W

Let me check I understand your example function;

You pass in a number 0 <= x < 16 and return a given value, is this the case?

(Firstly, and as an aside, playing directly with pc in this way is generally a bad idea as it stuffs up pipelining and will usually force a flush of the pipe, and in bad cases a flush of the cache, depending on which processor you are using. It's also a pain to port as you can be caught if the pipeline length changes.).

In your specific case this function is completely trivial and actually is just add 0x3C to W, so that's your single exit point in that case.

In the case that you want some less mathematically predictable values for each entry then this is just a look up table. Most processors let you load from an offset from a base address in one or two instructions, so do that.

In neither case should you actually need a function at all. Let alone a 'clever' on which messes directly with pc.

Bah.

Forums

Forgotten password

Opinion

euros_channel_money

Tim Worstall

Time to take a sniff at the coffee, perhaps
joe_tucci_emc_channel

Chris Mellor

Will they have to drag him back like last time?
chain_relationship_channel

Features

cloud_accounting
Playing the SLA long game
channel_teaser_money_top
cloud computing Fight
Applications must work for the cloud to float
Paul Cormier, Red Hat
How a Unix killer crawled from the dot-com bust