# LC-3 - Detect Min and Max Numbers

I was wondering how I could detect the min and max of a list of 12 numbers using LC-3 Assembly code. Any help would be appreciated. Thanks in advance.
«1

• : I was wondering how I could detect the min and max of a list of 12 numbers using LC-3 Assembly code. Any help would be appreciated. Thanks in advance.
:
Does anyone know how I could do this? How would I do an array or even compare two numbers to see which one is larger/smaller? I would appreciate any help.
• : I was wondering how I could detect the min and max of a list of 12 numbers using LC-3 Assembly code. Any help would be appreciated. Thanks in advance.
:

[code]var min = MAX_VAL; // largest possible value for an element
var max = MIN_VAL; // smallest " " " " "

for p = 0 to 11
if min < list[p] then min = list[p];
if max > list[p] then max = list[p];
next p[/code]
• : : I was wondering how I could detect the min and max of a list of 12 numbers using LC-3 Assembly code. Any help would be appreciated. Thanks in advance.
: :
:
: [code]var min = MAX_VAL; // largest possible value for an element
: var max = MIN_VAL; // smallest " " " " "
:
: for p = 0 to 11
: if min < list[p] then min = list[p];
: if max > list[p] then max = list[p];
: next p[/code]
:

Thanks for the reply but the assembler language I'm using only has AND, ADD, NOT. It doesn't have "if" and "<>". If it did, this would be so much easier. Lol. I actually figured out the program since I submitted the request. Thanks though.

-Brian
• You've figured it out?
I am still tyring to work it out. I have the code and it should work, but the simulator is doing something weird... we can't figure it out.
!!!!

-court

: : : I was wondering how I could detect the min and max of a list of 12 numbers using LC-3 Assembly code. Any help would be appreciated. Thanks in advance.
: : :
: :
: : [code]var min = MAX_VAL; // largest possible value for an element
: : var max = MIN_VAL; // smallest " " " " "
: :
: : for p = 0 to 11
: : if min < list[p] then min = list[p];
: : if max > list[p] then max = list[p];
: : next p[/code]
: :
:
: Thanks for the reply but the assembler language I'm using only has AND, ADD, NOT. It doesn't have "if" and "<>". If it did, this would be so much easier. Lol. I actually figured out the program since I submitted the request. Thanks though.
:
: -Brian
:
• : You've figured it out?
: I am still tyring to work it out. I have the code and it should work, but the simulator is doing something weird... we can't figure it out.
: !!!!
:
: -court
:
:
: : : : I was wondering how I could detect the min and max of a list of 12 numbers using LC-3 Assembly code. Any help would be appreciated. Thanks in advance.
: : : :
: : :
: : : [code]var min = MAX_VAL; // largest possible value for an element
: : : var max = MIN_VAL; // smallest " " " " "
: : :
: : : for p = 0 to 11
: : : if min < list[p] then min = list[p];
: : : if max > list[p] then max = list[p];
: : : next p[/code]
: : :
: :
: : Thanks for the reply but the assembler language I'm using only has AND, ADD, NOT. It doesn't have "if" and "<>". If it did, this would be so much easier. Lol. I actually figured out the program since I submitted the request. Thanks though.
: :
: : -Brian
: :
:
Hi. I got problem with that too, can you put the code for me to detect min and max numbers ? Thanks
• What are you getting for your values? I had a problem with it, but I ended up Breaking the program at the HALT command in the simulator and that fixed the problem. See if that helps.

-Brian

: You've figured it out?
: I am still tyring to work it out. I have the code and it should work, but the simulator is doing something weird... we can't figure it out.
: !!!!
:
: -court
:
:
: : : : I was wondering how I could detect the min and max of a list of 12 numbers using LC-3 Assembly code. Any help would be appreciated. Thanks in advance.
: : : :
: : :
: : : [code]var min = MAX_VAL; // largest possible value for an element
: : : var max = MIN_VAL; // smallest " " " " "
: : :
: : : for p = 0 to 11
: : : if min < list[p] then min = list[p];

: : : if max > list[p] then max = list[p];
: : : next p[/code]
: : :
: :
: : Thanks for the reply but the assembler language I'm using only has AND, ADD, NOT. It doesn't have "if" and "<>". If it did, this would be so much easier. Lol. I actually figured out the program since I submitted the request. Thanks though.
: :
: : -Brian
: :
:

• Hmm, I am not sure if this is right plz check it for me
.orig x3000

and r0,r0,#0 ;clear

and r1,r1,#0 ;clear

and r2,r2,#0 ;clear

and r3,r3,#0 ;clear

and r4,r4,#0 ;clear

LD r1,#9 ;load A into R1

LD r2,#9 ;load B into R2

NOT r3,r2 ;NOT B for complement

BRn NEG ;Branch if neg

BRnzp STOP ;go to STOP

STOP halt

.orig x3000

and r0,r0,#0 ;clear

and r1,r1,#0 ;clear

and r2,r2,#0 ;clear

and r3,r3,#0 ;clear

and r4,r4,#0 ;clear

LD r1,#9 ;load A into R1

LD r2,#9 ;load B into R2

NOT r3,r2 ;NOT B for complement

BRp POS ;Branch if positive

BRnzp STOP ;go to STOP

STOP halt
.end

and I suppose to have maximum value R0 and minimum value R1.

• If u can, can u send the code or the *.asm ur file to me, so i can see it? thanks (email address is nhuhai18@yahoo.com)
• I thought you were a PRO at LC3...Lol. Anyways, this was for a homework assignment and I don't want to get in trouble for having two of the same program. I'm sure you're in my class cause not too many people need a LC3 program that finds the min/R1 and max/R0. You need a way for it to go back and check the value R3 to see if the next number is bigger or smaller than it. Right now you just have it check once. Unless you only have to check one number and not 12.

-Brian

: Hmm, I am not sure if this is right plz check it for me
: .orig x3000
:
: and r0,r0,#0 ;clear
:
: and r1,r1,#0 ;clear
:
: and r2,r2,#0 ;clear
:
: and r3,r3,#0 ;clear
:
: and r4,r4,#0 ;clear
:
: LD r1,#9 ;load A into R1
:
: LD r2,#9 ;load B into R2
:
: NOT r3,r2 ;NOT B
for complement
:
:
:
: BRn NEG ;Branch if neg
:
:
: BRnzp STOP ;go to STOP
:
:
: STOP halt
:
: .orig x3000
:
: and r0,r0,#0 ;clear
:
: and r1,r1,#0 ;clear
:
: and r2,r2,#0 ;clear
:
: and r3,r3,#0 ;clear
:
: and r4,r4,#0 ;clear
:
: LD r1,#9 ;load A into R1
:
: LD r2,#9 ;load B into R2
:
: NOT r3,r2 ;NOT B for complement
:
:
:
: BRp POS ;Branch if positive
:
:
: BRnzp STOP ;go to STOP
:
:
: STOP halt
: .end
:
: and I suppose to have maximum value R0 and minimum value R1.
:
:
:
:

• oooh, u in my class ? Oo which university u @, what class u in?
• Intro to Computing @ the University of Arkansas.
• : Intro to Computing @ the University of Arkansas.
lol , kk u in my class lol , omg !! did u turn in ur homework lol, I got it I think but do u mind checking it for me?

.orig x3000

and r0,r0,#0

and r1,r1,#0

and r2,r2,#0

and r3,r3,#0

and r4,r4,#0

LD r1,#9
LD r2,#9

NOT r3,r2

BRn NEG

BRnzp STOP

and r0,r0,#0

and r1,r1,#0

and r2,r2,#0

and r3,r3,#0

and r4,r4,#0

LD r1,#9

LD r2,#9

NOT r3,r2

BRp POS

BRnzp STOP

STOP halt

.end

• From what I see, this would calculate the min and max of one number. I don't see where you are getting your 12 numbers from. Also, it doesn't go back to the compare statement ever. It just goes to the NEG, POS and STOP. You need to change your R3 (I believe) to the next number in the list and compare that with your current min and max to see if it is greater or smaller than those, then replace if it is or skip if it isn't. I'm actually heading to bed now. I hope this helps some. Sorry I couldn't help more. Good luck on it though and study for the test

-Brian

: : Intro to Computing @ the University of Arkansas.
: lol , kk u in my class lol , omg !! did u turn in ur homework lol, I got it I think but do u mind checking it for me?
• Good luck to u too man. thanks for the instrution
• [b][red]This message was edited by NFF at 2004-10-25 2:10:44[/red][/b][hr]
: If u can, can u send the code or the *.asm ur file to me, so i can see it? thanks (email address is nhuhai18@yahoo.com)
:

Hello,were doing something similar, but instead we're trying to get letter in alphbetical order (by hex) and was wondering if u could post your code here to find max and min numbers. I have no idea how to do it.
Like for example lets say we have letter s in location x30F0 and a in location x30F1 and an o in location x30F2. the hex values for these letters are x0073 x0061 and x006F. I think your program will give me an idea on mine