-1

How many instructions could fit into a 256-byte memory unit, given a 32-bit architecture?

Could someone explain how you get this answer? I know each instruction is 32 bits. I know the answer is 9 but I don't know how to get that answer

1 instruction = 32 bits = 4 bytes.

Then 256/4 = 64.

What I would like an explanation if possible is what difference it makes if it is 32-bit architecture. That refers to the instruction right? In other words, if it said a 64-bit architecture would that mean; each instruction is 64 bits = 8 bytes so then only 32 instructions would fit.

Am I correct?

Thanks!

  • No, processor instructions aren't tied to bitness of the architecture. x86, for example, has variable-length instructions. Also this is question is very unclear and vague. – milleniumbug Aug 07 '16 at 18:36
  • You're saying the answer is 64 instructions in 256 **mega**bytes? So each instruction is 4MiB long? On x86, the right answer is one instruction per byte. On something like MIPS with 32-bit fixed-length instructions, the answer is 256MiB / 4B = 2^28 / 2^2 = 2^26 instructions. – Peter Cordes Aug 07 '16 at 18:40
  • @PeterCordes OP says each instruction is 32 bits. IOW, `(4 bytes) * 64 = 256 MB`. The math works out perfectly fine. Yeah. – Mysticial Aug 07 '16 at 18:42
  • @mystical: um no -- `4 bytes * 64 = 256 bytes`. Not `256 MB`; very different. – Chris Dodd Aug 07 '16 at 18:49
  • 1
    I think my instructor made a mistake and he meant 256 bytes instead of 256MB. Because only with 256 megabytes it would make sense. Thank you all for your help. I also think when he wrote 32 bit architecture he meant about the instruction, now some instructions are 64 bits. – Pierina Camarena Aug 07 '16 at 18:55
  • No, you're not correct about instruction sizes on 64-bit architectures. You haven't narrowed things down enough to say anything more specific than that. Also 9 instructions isn't even a power of 2, so that makes zero sense. This question is just turning into total nonsense. – Peter Cordes Aug 08 '16 at 01:27

1 Answers1

2

A 32 bit architecture does not necessarily use 32 bit long instructions. The 32 bit only tells you, that memory addresses are 32 bit long so 232 addresses are possible (232 Byte = 4GiB) and registers can store equally many bits.

Instructions can have variable length depending on your architecture.

For example if you have an x86 architecture (16, 32 or 64 bit), instructions have a variable length. The maximum length is theoretically unlimited. In the real world, instructions on x86 machines are limited to 15 bytes. (See this answer)

If the 15 byte limit applies, the minimum number of instructions, which can be stored in a 256 Byte memory unit is ⌊256/15⌋=17 instructions. The shortest possible instructions on an x86 machine are just 1 Byte long, so 256 instructions would fit. (x86 Wikipedia article)

If you are using a RISC architecture (reduced instruction set), often instructions do have a fixed length. For example, the ARM architecture initially used only 32 bit instructions, so 256/4=64 instructions would fit into your memory unit. Current versions of ARM (32 bit or 64 bit) have 32 and 16 bit long instructions to increase code density, so up to 128 instructions could theoretically fit in your memory unit. (ARM Wikipedia article)

Community
  • 1
  • 1
Palle
  • 11,511
  • 2
  • 40
  • 61