This is more than of a concept question. My understanding of assembly is express and only in terms of MIPS, so excuses me if this does not use to other assembly architectures.

Allow'due south say someone needed a lot of values to be stored. I can't think of a situation when someone actually needs that many registers and tin't store them somewhere, merely allow's assume a hypothetical one.

Where tin y'all store your data?

user avatar

Peter Cordes

279k 41 gold badges 505 silverish badges 714 bronze badges

asked December 9, 2016 at 22:01

user avatar

2

  • well, you cant...you lot have a limited number of registers, all the other information has to live elsewhere (ram/rom) and you swap it out as needed. you lot cant have too many instructions in the pipe at the aforementioned time anyhow and then you just have to deal with the limitations of the processor. Some processors accept dozens to hundreds of registers, you could switch to 1 of those.

    December 9, 2016 at 22:xl

  • Every bit far as I can tell, the MIPS compages has a stack, too. Encounter these notes.

    Dec 11, 2016 at 17:32

2 Answers 2

The question says "and tin can't store them somewhere", which I assumed meant you tin can't only spill them to the stack similar compilers normally practice with local variables when they run out of registers.

"Clever" alternatives (which you should only use in special cases where storing on the stack or in another reserved retention location):

  • pack multiple values into each register. eastward.g. if you know your information fits in 16 bits, you could pack 4 16-bit integers into a 64-bit general-purpose integer register. Y'all'd need a couple registers free to manipulate your data (e.g. unpacking with shift and AND instructions and and so doing something, earlier re-packing).

  • put information technology into floating-point or vector registers. (If the FP hardware doesn't mistake, flush denormals to zero, or otherwise munge arbitrary flake-patterns, then just move your integer information equally-is. Don't actually do an integer->float conversion.)

answered December 11, 2016 at 19:53

user avatar

user avatar

answered Dec 10, 2016 at 0:17

user avatar

7

  • "The ECX/CX registers store referenceable values." What does that mean? Obviously your answer is about the x86, but in that location is nothing particularly special about ECX/CX when information technology comes to the stack on x86. The only interesting thing about this register is that it is frequently used as a loop counter, just that has nothing to do with the stack. Were you thinking of a dissimilar register, possibly, similar the stack pointer (ESP/SP)?

    Dec 11, 2016 at 17:34

  • No. They can be used for "indexing" values of arrays. Take a look at the example, lamentable most my phrasing. I'm not entirely sure what the all-time judgement for this would be. However, it does work for when yous need to shop many values. It's really how a compiler compiles to associates. Information technology reserves just plenty space for the variables it needs as an assortment. And so has a base pointer and a pointer or indexer. This allows programs to shop variables in assembly. Go on in mind this is Intel syntax in my answer.

    Dec xi, 2016 at 17:59

  • You tin (at least assuming we're talking well-nigh 32-bit code) use whatsoever register as an index. There is nothing special about ECX. And there sample code you lot linked to isn't really using information technology as an indexer at all. Nor is it showing how to use the stack. It'due south just reading from an array of byte values. The code wouldn't work for the stack without modification; they grown top-downwardly on x86. A C compiler would actually compile lawmaking that uses the stack, reserving space using either a Push or SUB instruction at the summit of the routine.

    Dec 11, 2016 at 18:03

  • I didn't know that you could utilize any register every bit an index, what I constitute online was unlike. I'grand relatively new to Assembly besides, so exercise you mind telling me how a stack might work?

    Dec 11, 2016 at 18:10

  • Well, it is a rather big topic. Lots of information online, of course. Like this Wikibook. I'm non certain what y'all found online regarding registers. Almost of what I'd imagine you'd come across for "index" register would be ESI and EDI, which certain instructions (in particular, the CISC string instructions) utilize as source and destination indexes, respectively. Lots of skillful tutorials on x86 assembly in the x86 tag wiki, here.

    December 11, 2016 at 18:xiii

Not the answer you're looking for? Browse other questions tagged associates mips or ask your own question.