Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 3rd, 2005, 3:40 AM   #1
alanlaw
Newbie
 
Join Date: Feb 2005
Posts: 3
Rep Power: 0 alanlaw is on a distinguished road
Hypothetical Processor, Question

Right off the bat, I have to say this is a homework question. I've
read the rules about posting homework questions so I will do my best to show you that I have indeed worked over this problem.

To sum it up, my problem is to translate a series of hypothetical assembly instructions into binary.

NOTE: in the process of formatting this post, copying it from notepad has made it look funky

Some rules:

There are four registers: AX, BX, CX, DX

Each instruction can be either 1 byte or 3 bytes.

The first three bits are resigned for translation of the opcode
The next two bits are resigned for the first operand
The next three bits are resigned for the second operand
The last 16 bits are resigned for memory/constants/address/label

example:
mov DX, 0		110 11 111 0000000000000000

Key for translating:
iii (instruction group) --------- mmm(depends on iii)
000 => special ----------------- AX
001 => or --------------------- BX
110 mov reg, /memory/constant [xxxx] <---memory address

mmm (second operand, depend on iii)

rr(first operand)
00 => AX
01 => BX
10 => CX
11 => DX

This is certainly not all of it, but my only problem is with translating an instruction like mov BX, AX.

I get about as far as: 110 01 But I'm at a lose at translating [xxxx],
especially since mov BX, AX is a one byte instruction, giving me only 3
bits to work with.

Thanks in advance for any help.
alanlaw is offline   Reply With Quote
Old Oct 3rd, 2005, 6:53 AM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Your information is terribly incomplete or unclear, one. You don't describe the third set of bits in the opcode at all, or you have them labeled as an operand. A reasonable guess would be:

110 00 001
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Oct 3rd, 2005, 12:46 PM   #3
alanlaw
Newbie
 
Join Date: Feb 2005
Posts: 3
Rep Power: 0 alanlaw is on a distinguished road
As I said, I have left out alot of it, but I thought the general idea was conveyed. I did accidentally leave out that the mmm is the second operand or the third set of bits, sorry about that. My question was more about how 'in general' could your represent a memory location as binary when only given 3 bits. If you feel that my information is too incomplete, well then I can just drop it. Being new to Assembly, I may have overestimated the ability of people to understand the snipit of information that I wrote down.
alanlaw is offline   Reply With Quote
Old Oct 3rd, 2005, 1:19 PM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Don't get your shorts in a wad, I'm not the one putting out insufficient information. I would say you're overestimating people's psychic abilities, not their comprehension.

That said, here's the deal: you can't represent a memory location with 3 bits, unless you have very little memory. Registers aren't (normally) memory. They're storage locations local to the uP. If you have 8 of them, you have a pattern of 3 bits sufficient to identify each one individually.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Oct 3rd, 2005, 6:43 PM   #5
uman
Expert Programmer
 
Join Date: Dec 2004
Posts: 794
Rep Power: 4 uman is on a distinguished road
Don't mind DaWei, he's a cranky bastard.

Damn good programmer, but cranky bastard.

(Not that that's a bad thing DaWei :-P)
__________________
Few people deserve to be compared to (Rush) Limbaugh, most of them were convicted at the Nuremburg trials.
--WilliamSChips on Slashdot
uman is offline   Reply With Quote
Old Oct 6th, 2005, 4:37 AM   #6
alanlaw
Newbie
 
Join Date: Feb 2005
Posts: 3
Rep Power: 0 alanlaw is on a distinguished road
Quote:
Originally Posted by DaWei
Don't get your shorts in a wad, I'm not the one putting out insufficient information. I would say you're overestimating people's psychic abilities, not their comprehension.

That said, here's the deal: you can't represent a memory location with 3 bits, unless you have very little memory. Registers aren't (normally) memory. They're storage locations local to the uP. If you have 8 of them, you have a pattern of 3 bits sufficient to identify each one individually.
Alright, I'll keep my shorts out of a wad if you keep your panties un-wadded also. See? I can be condescending also.

Thanks.
alanlaw is offline   Reply With Quote
Old Oct 6th, 2005, 6:29 AM   #7
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
I'm expecting sensible rational questions from you, for which I have answers. You're wanting free advice and help without enabling such help. My crystal is in the shop for ball joints. You still got the best answer available with the limited information. My criticism was justified. Your response is puerile. You're unable to be condescending to me -- it implies a relationship you will probably never achieve.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Oct 6th, 2005, 8:18 PM   #8
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 852
Rep Power: 4 The Dark is on a distinguished road
So for MOV BX, AX wouldn't you just have
110 01 000

If you use the same instruction for memory addresses then you could use 100 in the second param to indicate that the instruction is 3 bytes and the 16 bit param is used for a constant, you could then use 101 to indicate a memory address
So MOV BX, 0xBEEF would be something like:
110 01 100 10111110 11101111

and MOV BX, [0xBEEF] would be something like:
110 01 101 10111110 11101111
The Dark is offline   Reply With Quote
Old Oct 6th, 2005, 8:32 PM   #9
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Be one or the other, but I don't see any indication as to whether it should be mov src, dst or mov dst, src.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:17 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC