-5

Write a Little Man program to accept an indefinite number of input values. The output value will be the largest of the input values. You should use the value 0 as a flag to indicate the end of input

This is what I have done so far.

INP

STA FIRST

BRZ ENDWH

BRA WHILE ENDWH HLT

ZERO

DAT

TEN

  • You're going to find that tag spamming (adding several tags that have no relevance to your post) isn't going to work out well for you here. Tags have specific meaning, and you should read and understand what that meaning is before adding them. None of the ones you've added have anything at all to do with the subject of your post. You've also not clearly explained a problem or asked any sort of specific question. (Posting your assignment and dumping code isn't a problem description, and *I don't think it's correct. I need help* is not any kind of question.) Try reading [ask] and then [edit]. – Ken White Feb 21 '20 at 23:52

1 Answers1

1
begin   INP
        BRZ end
        STA input
        SUB max
        BRP nmax
        BRA begin
nmax    LDA input
        STA max
        BRA begin
end     LDA max
        OUT
        HLT
input   DAT
max     DAT
Diadistis
  • 12,086
  • 1
  • 33
  • 55
  • How come it doesnt show the largest as the output of the input values? – Adil Maalim Feb 22 '20 at 00:32
  • @AdilMaalim can you elaborate? I have tested the code in https://www.101computing.net/LMC/ and works fine – Diadistis Feb 22 '20 at 00:34
  • It says on the question that " The output value will be the largest of the input values. " My guess that the output should show the largest value from the numbers that you input. – Adil Maalim Feb 22 '20 at 01:05
  • That is exactly what it does. I have left the `max` default so if you only enter negative numbers you will get 0 but you can initialize it at a negative number to cover this case. Have you tried it? What was the output vs the expected output? – Diadistis Feb 22 '20 at 01:12
  • I tried positive numbers and i can see the inputed values but on the output it doesnt show the largest value. I also tried negative numbers, i can see the inputed numbers and i included 0, on the output it shows 0 – Adil Maalim Feb 22 '20 at 01:15
  • So you're saying if i put any number and then include 0 in my input, the output should show the largest number i inputed – Adil Maalim Feb 22 '20 at 01:18
  • Yes : https://i.imgur.com/11rVBAM.png – Diadistis Feb 22 '20 at 01:20
  • I believe you but for some reason when i did it it doesnt work. C:\Users\Adil\Pictures\LMC.PNG – Adil Maalim Feb 22 '20 at 01:34
  • The code you posted and the one from the screenshot you sent me is a little bit different. Compare both of them – Adil Maalim Feb 22 '20 at 01:37
  • I can't see a picture on your computer... The only difference in the code in my screenshot is the `0` initial value of max which doesn't make any difference, you can try it out either way. How are you entering the numbers? – Diadistis Feb 22 '20 at 01:40
  • I entered the same numbers you typed from the screenshot and in the end it showed nothing in the output – Adil Maalim Feb 22 '20 at 01:41
  • Can you upload the screenshot somewhere? – Diadistis Feb 22 '20 at 01:43
  • https://imgur.com/a/t0paW6P – Adil Maalim Feb 22 '20 at 01:48
  • I'm not quite sure what browser (Brave maybe?) you're using and on what device but since this is a javascript implementation of the LMC it may have some kind of bug. – Diadistis Feb 22 '20 at 01:54
  • that's barve browser. I tried it on google chrome and its the same problem – Adil Maalim Feb 22 '20 at 01:56
  • I have tried it on a second simulator and it still works fine https://imgur.com/a/ddtsJg1 Can you check this one too? https://peterhigginson.co.uk/lmc/ – Diadistis Feb 22 '20 at 01:59
  • And a third one https://blog.paulhankin.net/lmc/lmc.html?program=YmVnaW4gICBJTlAKICAgICAgICBCUlogZW5kCiAgICAgICAgU1RBIGlucHV0CiAgICAgICAgU1VCIG1heAogICAgICAgIEJSUCBubWF4CiAgICAgICAgQlJBIGJlZ2luCm5tYXggICAgTERBIGlucHV0CiAgICAgICAgU1RBIG1heAogICAgICAgIEJSQSBiZWdpbgplbmQgICAgIExEQSBtYXgKICAgICAgICBPVVQKICAgICAgICBITFQKaW5wdXQgICBEQVQKbWF4ICAgICBEQVQ=&input=NQoyCjU0CjM0CjYKMAo= – Diadistis Feb 22 '20 at 02:01
  • @ Disdistis the third simulator with the blog works and also the second simulator works so i'm not sure what i'm doing wrong then. – Adil Maalim Feb 22 '20 at 02:37
  • I'm not sure either – Diadistis Feb 22 '20 at 02:57
  • I think it's fine. I will use what you gave including the screenshot so thank you. – Adil Maalim Feb 22 '20 at 03:01