
-----------------------------------
Numbah51
Tue Dec 01, 2009 1:38 am

Assembly Question
-----------------------------------
I have an assignment for architecture class and am getting confused with assembly.  The question is:

[code]
Write a subroutine cmp in assembly which compares two bytes. Namely, write
a segment of assembly code in the form of:
CMP: ...
...
...
RET
? Assume the two byte to be compared are already stored in register B and
C when the subroutine cmp is called.
? The return value is one of 0, 1, or 2. If the two bytes are equal, then
return 0. If first byte is less than the second, then return 1. Otherwise,
return 2.
? The return value is to be stored in register D.
[/code]

Thanks for any help
There were two solutions I came up with ... I'd just like some input if they are correct or some insight on how to fix them.

Solution 1
[code]
CMP A,B
JE MOV #0,D
JB MOV #1,D
JA MOV #2,D
RET
[/code]

Solution 2
[code]
CMP: cmp A,B
        JE equal
        JB less
        JA more
equal: MOV #0,D
less: MOV #1,D
more MOV #2,D
        RET
[/code]

-----------------------------------
Tony
Tue Dec 01, 2009 2:04 am

RE:Assembly Question
-----------------------------------
It would be helpful to know what architecture you are writing this for. Though regardless, there are no arguments for routines, as you assume to be attempting to do with
[code]
CMP A,B
[/code]
and since
[code]
MOV #0,D 
[/code]
is an opcode, then
[code]
JE MOV #0,D
[/code]
is not.

-----------------------------------
mirhagk
Tue Dec 08, 2009 3:04 pm

RE:Assembly Question
-----------------------------------
I know this is off-topic but does anyone know a tutorial where I can learn assembly, and how to use it??

-----------------------------------
apomb
Tue Dec 08, 2009 3:24 pm

RE:Assembly Question
-----------------------------------
here is a great place to search a ton of assembly language tutorials and examples: www.google.ca

-----------------------------------
jbking
Tue Dec 08, 2009 4:35 pm

Re: RE:Assembly Question
-----------------------------------
I know this is off-topic but does anyone know a tutorial where I can learn assembly, and how to use it??

[url=http://maven.smith.edu/~thiebaut/ArtOfAssembly/artofasm.html]The Art of Assembly Language Programming would probably be an example for you.

-----------------------------------
mirhagk
Mon Dec 14, 2009 2:42 am

RE:Assembly Question
-----------------------------------
thank you
