|
-
Apr 29th, 2003, 10:34 AM
#1
Thread Starter
New Member
Primitive CPU instructions
Primitive CPU Instructions
I am taking a computer architecture class in college. My graduation is pending that I pass this class. I have to develop a program consisting of primitive CPU instructions, such as NOT, AND, OR, XOR, ADD and shift.
My problem is that I don't understand what the procedure is asking to do. If I could just put the logic in plain words then Maybe I can develop the couple of lines of instructions to implement the procedure.....
integer i, a;
i = 0;
While (i<10) do
a = i*2;
i = i +1;
endwhile
Any help would be greatly appreciated, or any information on how I can obtain an understanding of the procedure as well
I am a desperate individual......
-
Apr 29th, 2003, 08:36 PM
#2
Lively Member
Well, I don't like doing other people's homework, but...
i = 0;
While (i<10) do
a = i*2;
i = i +1;
endwhile
This might do it:
Code:
; reset dx to 0 in 1 byte less than MOV dx,0
XOR dx,dx
; label
_loop:
; load 2 into ax
MOV ax,2
; multiply dx by 2, store in ax
MUL ax,dx
; add 1 to dx
INC dx
; compare to 10
CMP dx,10
; jump less than to the label
JB _loop
I haven't tested it and I am a little rusty with x86 ASM.
-AndySoft
[email protected]
[email protected] (Use the other one first!)
I use: NASM, HTML, Perl, PHP, JavaScript, Batch, TI-Basic (TI-83+), QBasic 1.1, QuickBASIC 4.5, QuickBASIC Extended 7.1, VB-WIN 6 Ent., and the rest of Visual Studio 6 Ent.  And who knows what else!
-
Apr 30th, 2003, 08:05 PM
#3
Thread Starter
New Member
Thank you very much fo the reply andysoft...but im afraid i can't use that
I have to use only primitive cpu instructions which are:
NOT
AND
OR
XOR
ADD
SHIFT
and it muxt be about 14 to 20 lines of code..such as..
move m1,r1
move m2, r2
move m3, r3
..and so on to cmplte the procedure..
my problem is that I don't understand what the procedure is actually trying to do
If i knew that then maybe I can try and put something together
Thank you very much for you help..it was appreciated
-
Apr 30th, 2003, 10:56 PM
#4
Fanatic Member
-
May 1st, 2003, 01:31 PM
#5
Hyperactive Member
Let me see if I can help. I dont know all the working of an x86 proc but I know the Intel assembly commands so I may not have the accumulators named right.
Here is your code
i = 0;
While (i<10) do
a = i*2;
i = i +1;
endwhile
ok, Basically all you are doing is initiallizing a location, in my example the accumulator, doing a multiply statement, increasing the count and exiting the loop after you reach 10.
here goes, again I am not sure of the exact names of the commands for an x86 but I will do my best to make them correct.
i - AX register
a - BX register
AND AX, 00h -Give us a zero for i
AND BX, 00h -same here for a
//Enter the loop
Loop1:
CMP AX, 0Ah -See if we have reached 10
JZ End - If we have then, we are done
AND BX, 00h -Clear out BX
OR BX, AX -Make BX and AX equal
SHL BX, 1 -Multiply by A by Two
ADD AX, 1 -Increment our counter
JMP Loop1
End:
END
That should do. When you multiply by 2, all you have to do is shift the location to the left. Also to divide by two, you would shift to the right.
I hope that helps you understand it. I dont think I have any errors there but then again, I did not try to compile it.
Jerel
-
May 2nd, 2003, 09:06 AM
#6
It isn't about working assembly as I see it, it is about using simple instructions.
The tricky thing is the loop. With the instructions you're allowed the only possible thing is to unroll the loop, unless you are allowed conditional jump instructions.
Unrolling the loop would result in this pseudocode:
Code:
i = 0;
a = i*2;
i = i +1;
a = i*2;
i = i +1;
a = i*2;
i = i +1;
a = i*2;
i = i +1;
a = i*2;
i = i +1;
a = i*2;
i = i +1;
a = i*2;
i = i +1;
a = i*2;
i = i +1;
a = i*2;
i = i +1;
a = i*2;
i = i +1;
Which easily converts to this assembly:
Code:
xor eax, eax
mov ebx, eax
shl ebx, 1
inc eax
mov ebx, eax
shl ebx, 1
inc eax
mov ebx, eax
shl ebx, 1
inc eax
mov ebx, eax
shl ebx, 1
inc eax
mov ebx, eax
shl ebx, 1
inc eax
mov ebx, eax
shl ebx, 1
inc eax
mov ebx, eax
shl ebx, 1
inc eax
mov ebx, eax
shl ebx, 1
inc eax
mov ebx, eax
shl ebx, 1
inc eax
mov ebx, eax
shl ebx, 1
inc eax
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
May 3rd, 2003, 02:47 PM
#7
Lively Member
I'd use ax and bx so it works on an 80286.
-AndySoft
[email protected]
[email protected] (Use the other one first!)
I use: NASM, HTML, Perl, PHP, JavaScript, Batch, TI-Basic (TI-83+), QBasic 1.1, QuickBASIC 4.5, QuickBASIC Extended 7.1, VB-WIN 6 Ent., and the rest of Visual Studio 6 Ent.  And who knows what else!
-
May 4th, 2003, 11:20 AM
#8
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|