Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Assembly Question
Index -> General Programming
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Numbah51




PostPosted: Tue Dec 01, 2009 1:38 am   Post subject: 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.


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


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
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Tue Dec 01, 2009 2:04 am   Post subject: 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

and since
code:

MOV #0,D

is an opcode, then
code:

JE MOV #0,D

is not.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
mirhagk




PostPosted: Tue Dec 08, 2009 3:04 pm   Post subject: 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




PostPosted: Tue Dec 08, 2009 3:24 pm   Post subject: RE:Assembly Question

here is a great place to search a ton of assembly language tutorials and examples: www.google.ca
jbking




PostPosted: Tue Dec 08, 2009 4:35 pm   Post subject: Re: RE:Assembly Question

mirhagk @ Tue Dec 08, 2009 1:04 pm wrote:
I know this is off-topic but does anyone know a tutorial where I can learn assembly, and how to use it??


The Art of Assembly Language Programming would probably be an example for you.
mirhagk




PostPosted: Mon Dec 14, 2009 2:42 am   Post subject: RE:Assembly Question

thank you
Display posts from previous:   
   Index -> General Programming
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: