•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Assembly section within the Software Development category of DaniWeb, a massive community of 456,578 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,647 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Assembly advertiser: Programming Forums
Views: 962 | Replies: 1
![]() |
•
•
Join Date: Nov 2007
Posts: 13
Reputation:
Rep Power: 2
Solved Threads: 0
I am trying to write a code in LC-3 for finding the minimum and maximum values entered. So far I have completed what is below but am missing some major parts and I can't figure out what to do. ---- the lines like this is where I know something is needed. Is there ANYONE CAN HELP ME?????? please please please
.ORIG 0x3000
;R0 = MIN
;R1 = MAX
;R2 = ADDRESS OF DATA----INCREMENT THIS IN PLACE--TREAT AS COUNTER OF SORTS
;R3 = COUNTER current value
;R4 = COMPARATOR (-COUNT)
;R6 = - DATA VALUE
;R5 = TEST VALUE
LEA R2, DATA
LDR R0, R2, #0
LDR R1, R2, #0
AND R3, R3, #0 ; CLEAR R3
LEA R4, COUNT
LDR R4, R4, #0
NOT R4, R4
ADD R4, R4, #1
TEST ADD R7, R3, R4 ; SETS C.C NZP
BRzp QUIT
;COMPARISON TO MIN (R0)
;COMPARISON TO MAX (R1)- VALUE TO NEGATE IS DATA VALUE FROM BELOW
;
ADD R3, R3, #1
BRnzp TEST
----
QUIT RTN
LDR r6, r2, #0
negate r6
add r7, r0, r6
-
-
-
add r7, r1, r6
-----
COUNT .FILL 10
DATA .FILL 1
.FILL 2
.FILL 3
.FILL 4
.FILL 5
.FILL 6
.FILL 7
.FILL 8
.FILL 9
.FILL 10
.END
.ORIG 0x3000
;R0 = MIN
;R1 = MAX
;R2 = ADDRESS OF DATA----INCREMENT THIS IN PLACE--TREAT AS COUNTER OF SORTS
;R3 = COUNTER current value
;R4 = COMPARATOR (-COUNT)
;R6 = - DATA VALUE
;R5 = TEST VALUE
LEA R2, DATA
LDR R0, R2, #0
LDR R1, R2, #0
AND R3, R3, #0 ; CLEAR R3
LEA R4, COUNT
LDR R4, R4, #0
NOT R4, R4
ADD R4, R4, #1
TEST ADD R7, R3, R4 ; SETS C.C NZP
BRzp QUIT
;COMPARISON TO MIN (R0)
;COMPARISON TO MAX (R1)- VALUE TO NEGATE IS DATA VALUE FROM BELOW
;
ADD R3, R3, #1
BRnzp TEST
----
QUIT RTN
LDR r6, r2, #0
negate r6
add r7, r0, r6
-
-
-
add r7, r1, r6
-----
COUNT .FILL 10
DATA .FILL 1
.FILL 2
.FILL 3
.FILL 4
.FILL 5
.FILL 6
.FILL 7
.FILL 8
.FILL 9
.FILL 10
.END
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation:
Rep Power: 13
Solved Threads: 193
First, a short rant. Professors love to use stuff like this because it doesn't exist in real life and nobody will know how to help you (or help you cheat... but I won't do that). I had to go download all the stuff off of your textbook's website to learn about PC-3 (which, IMAO, is one of the most underpowered assembly languages I've ever seen). If they want to teach MIPS assembly, why not just use actual MIPS assembly?!!!
/end rant
The trick with assembly language is to think in fairly large terms, then for each term write a small series of instructions. You have already got a fairly good start. I'm not sure what you are doing after you RTN, but here are some thoughts on the min and max functions you are having trouble with. I will focus on R0 (min).
You've already got the current min in R0.
Each time through the loop you need to increment R2 by one, and load R5 with the value at R2.
Now, copy R5 to R6 and negate R6 like you did for the comparitor.
Add it to R0, and check the result to see whether you are greater-than-or-equal-to R0. If so, you can safely jump to the next part where you will test the max (R1). Otherwise, make R0 equal to R5.
When testing for max, do the same sort of thing: if you test less-than-or-equal-to R1, jump to the part that does the loop (where you add one to R3 and branch if necessary).
Beware, since you started out with min and max both equal to the first DATA element, you are only comparing nine numbers, not ten. So your counter and comparator need to have the correct value.
Also, if you are required to print the results, remember that TRAP OUT prints the ASCII value in R0.
Hope this helps.
/end rant
The trick with assembly language is to think in fairly large terms, then for each term write a small series of instructions. You have already got a fairly good start. I'm not sure what you are doing after you RTN, but here are some thoughts on the min and max functions you are having trouble with. I will focus on R0 (min).
You've already got the current min in R0.
Each time through the loop you need to increment R2 by one, and load R5 with the value at R2.
ADD R2, R2, 1LDR R5, R2, 0Now, copy R5 to R6 and negate R6 like you did for the comparitor.
Add it to R0, and check the result to see whether you are greater-than-or-equal-to R0. If so, you can safely jump to the next part where you will test the max (R1). Otherwise, make R0 equal to R5.
When testing for max, do the same sort of thing: if you test less-than-or-equal-to R1, jump to the part that does the loop (where you add one to R3 and branch if necessary).
Beware, since you started out with min and max both equal to the first DATA element, you are only comparing nine numbers, not ten. So your counter and comparator need to have the correct value.
Also, if you are required to print the results, remember that TRAP OUT prints the ASCII value in R0.
Hope this helps.
Last edited by Duoas : Nov 3rd, 2007 at 12:59 am.
![]() |
•
•
•
•
•
•
•
•
DaniWeb Assembly Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Dual-Boot (Multiboot), 9x-2000, 9x-XP (Windows tips 'n' tweaks)
- finding the maximum and minimum (C++)
- Qs about C++ variable types (C++)
- Help - Problem with array (C)
- Error while trying the update query (ASP)
- Check existing users in the database (ASP)
- something worng with my program need help please,, (C++)
- allows a user to put a maximum and minimum price and see all properties in that price (C++)
- basic fstream stuff (C++)
Other Threads in the Assembly Forum
- Previous Thread: Protected mode reboots
- Next Thread: beginner...



Linear Mode