Programming help please

*** IMPORTANT - PLEASE PLEASE PLEASE DO NOT GIVE ME THE ANSWER ***

I have to work out an answer for a computer class but I need some help - rather than an outright answer can I please get some help on HOW to work out the answer.

Your are designing an instruction set for your computer. All the instructions are of the same size (11 bits long). The size of an address field is 4 bits. You have already designed five 2 address instructions and 40 one address instructions. How many 0 address instructions can you still fit? Justify your answer.

Also just for context - this is me right now

Is that correct or should that be: five 2 address instructions?

1 Like

Yes - it should - and now it does!

Good catch!

fit in what? What is the limitation?

OK, but what i see is

so that is not really connected with the address count or whatever...
If i am wrong, and your limit is the address count, then it's basic math...

This is where I get confused - I have written out the question exactly as it was given to me.

I have to assume the address field but I think the question is poorly worded.

OK. I've come up with something. In order to do that type of encoding, you need variable OpCode lengths.

2 address instructions:

| 10 OpCode 8 | 7 Address A 4 |  3 Address B 0 | -> 3 bits + 4 bits + 4 bits = 11 bits

OK. Encode five instructions with 3 bits:

111, 110, 101, 100, 011

1 address instructions:

| 10 OpCode 4 | 3 Address 0 | -> 7 bits + 4 bits = 11 bits

Now comes the interesting part:

We can only use instructions having the high bits: 010, 001, 000

That means:
An instruction like: 11111111111 cannot exist as an one address instruction anymore - the computer couldn't tell the difference between 111 1111 1111 as a two address instruction and 1111111 1111 being an one address instruction.
Therefore only instructions like 010XXXX XXXX, 001XXXX XXXX and 000XXXX XXXX are allowed here. There are 48 of them available: 010XXXX + 001XXXX + 000XXXX = 48 since 2^4 + 2^4 + 2^4 = 48.

This is now causing an issue: Now we are unable to tell the difference between an one address instruction and a zero address instruction - all two and one address instructions start with one of the 2^3 options in their high bits - so we need more encoding.

Let's say, one address instructions are now only allowed to have an OpCode like: 010XXXX, 001XXXX or 0001XXX.
That means: There are now only 010XXXX + 001XXXX + 0001XXX = 2^4 + 2^4 + 2^3 = 40 options available.
Perfect! We only need 40 one address instructions.

OK. Now let's encode our zero address instructions which can only start with 0000 in their high bits.
We have no address in our instruction anymore, so the entire instruction can be an OpCode but since we are only able to use: 0000 XXXX XXX we only have 2^7 = 128 OpCodes left.

So we can encode 128 zero address instructions, if there is no added immediate.
And that's hopefully the answer of that question - otherwise, ignore this post: I just did some research and maths for 2 hours and had no class about it.

EDIT: My brain feels damaged now.

@Vandal85 could you please post here if this answer is correct, when you've talked about the question in class?

1 Like

More than happy to post if thats correct. However because it's distance learning i wouldnt expect a reply for a month or so.

Thanks very much to everyone who helped!

OK running into a problem that either needs clarafication or something...

If the bit width is 11 and the address field uses 4 bits - doesnt that meant that the 5x3 bit would look like

[0111][XXXX XXX]
[0110][XXXX XXX]
[0101][XXXX XXX]
[0100][XXXX XXX]
[0011][XXXX XXX]

and the 40x1 bit

[0010][XXXX XXX] - 2^4 = 16
[0001][XXXX XXX] 2^4 = 16
[0000][XXXX XXX] 2^3 = 8

BUT if the address field is [0000] doesnt that make it a 0 bit address field?

and therefore isnt one of those 128 opcodes already used by the last 40x1 bit field? And how would you tell teh difference between the third 1 bit field and the 0 bit fields?

I think you are confusing something here.

It is not: [Address field][Immediate]

But:

[OpCode][Address A][Address B]
[OpCode][Address A]
[OpCode]

An address is 4 bits in size.
The size of the instruction is 11 bits.
Therefore the OpCode is variable:

2 address instruction: 3 bits
1 address instruction: 7 bits - with limitations -> 3 and 4 bits
0 address instruction: 11 bits - with limitations -> 7 bits

OC = OpCode
AdX = Address X <- These are the address fields with a size of 4 bits

2 address instructions:

OC |Ad1 |Ad2
111 XXXX XXXX
110 XXXX XXXX
101 XXXX XXXX
100 XXXX XXXX
011 XXXX XXXX

1 address instructions:

OC      |Ad1
010 XXXX XXXX
001 XXXX XXXX
000 1XXX XXXX

0 address instructions:

OC           |
000 0XXX XXXX
3 Likes

AH!!

Now I get it!!

HOO---FUCKING----RAY!!!!!!!!!

Two of the resources I used:
http://www.c-jump.com/CIS77/CPU/IsaDesign/index.html

1 Like

what class is this for? in my classes we brushed over this but didn't actually get into it.

1 Like

Im doing my Bachelor of IT with a Sys-Admin specialisation

Whats making it so difficult for me is that I'm doing it via distance education and my Lecturer is Indian and only records the lectures in 144p so its damn near impossible to understand him or even see what the hell is happening.

Oh and just for clarafication im not at all racist - but an audio recording in poor quality of someone with a strong accent, unusual sentence syntax and unusual grammar complicates the issue

That's true. Indians only use English since there are over 100 different dialects of Indian languages - sadly they combine both languages in ways that can be nearly impossible to understand.

1 Like

if that was racist then almost everyone in America would be. My wife can’t understand my dad when he speaks English to her. We are Spaniards.

Coming from a culture that interacts with many different languages, don’t feel bad... After my 3rd Indian professor i can understand them just fine.

1 Like

must have been in the initial classes, i just never noted it

hi can u please help me..

The OP himself needed help. Could you please provide more information what you need help with? If it's the same question the OP had before, see: https://forum.teksyndicate.com/t/programming-help-please/101230/9

@aadi123 I just saw, you joined a few minutes ago. Welcome to the forum! If you have a question related to programming, please create a topic for that question and put it into one of the categories under "Development" or into the "Code" category. Also, please read our community guidelines: https://forum.teksyndicate.com/t/welcome-new-users-read-for-rules-help-bugs-and-where-we-put-the-game-servers/74616

@Vandal85 could you please move this topic to the Development category? - It doesn't fit Software & Operating Systems.

I abused my powers and moved it. :P

3 Likes

@Ohban Well i finally got my marks back - 100% so thank you very much (and everyone else) for the help. Once it was explained to me in a way I understood I was able to understand the result.

1 Like