Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

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

Comments

  • BCBomb47BCBomb47 Member Posts: 8
    : 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.
  • sigma_zksigma_zk Member Posts: 68
    : 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]
  • BCBomb47BCBomb47 Member Posts: 8
    : : 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
  • theredqueen009theredqueen009 Member Posts: 1
    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
    :
  • LC3PROLC3PRO Member Posts: 16
    : 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
  • BCBomb47BCBomb47 Member Posts: 8
    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
    : :
    :

  • LC3PROLC3PRO Member Posts: 16
    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

    ADD r3,r3,#1 ;ADD #1 for 2's complement

    ADD r4,r1,r3 ;ADD A and B

    BRn NEG ;Branch if neg

    ADD r0,r0,r1 ;positive so load R1 into R0

    BRnzp STOP ;go to STOP

    NEG ADD r0,r0,r2 ;negative so load R2 into R0

    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

    ADD r3,r3,#1 ;ADD #1 for 2's complement

    ADD r4,r1,r3 ;ADD A and B

    BRp POS ;Branch if positive

    ADD r0,r0,r1 ;positive so load R1 into R0

    BRnzp STOP ;go to STOP

    POS ADD r0,r0,r2 ;negative so load R2 into R0

    STOP halt
    .end

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



  • LC3PROLC3PRO Member Posts: 16
    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)
  • BCBomb47BCBomb47 Member Posts: 8
    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
    :
    : ADD r3,r3,#1 ;ADD #1 for 2's complement
    :
    : ADD r4,r1,r3 ;ADD A and B
    :
    : BRn NEG ;Branch if neg
    :
    : ADD r0,r0,r1 ;positive so load R1 into R0
    :
    : BRnzp STOP ;go to STOP
    :
    : NEG ADD r0,r0,r2 ;negative so load R2 into R0
    :
    : 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
    :
    : ADD r3,r3,#1 ;ADD #1 for 2's complement
    :
    : ADD r4,r1,r3 ;ADD A and B
    :
    : BRp POS ;Branch if positive
    :
    : ADD r0,r0,r1 ;positive so load R1 into R0
    :
    : BRnzp STOP ;go to STOP
    :
    : POS ADD r0,r0,r2 ;negative so load R2 into R0
    :
    : STOP halt
    : .end
    :
    : and I suppose to have maximum value R0 and minimum value R1.
    :
    :
    :
    :

  • LC3PROLC3PRO Member Posts: 16
    oooh, u in my class ? Oo which university u @, what class u in?
«1
Sign In or Register to comment.