[Community Puzzle] MCxxxx microcontroller simulation

Coding Games and Programming Challenges to Code Better

Send your feedback or ask for help here!

Created by @Exanc,validated by @Adam798,@kayou and @jordan_codingame.
If you have any issues, feel free to ping them.

I can not succeed in only one test = digit manipulation II
Could someone explain to the dst instruction with an example please ?

→ DST ACC DAT with ACC = 0 and DAT = 9, what are the values of ACC ans DAT after ?

1
9
4
mov x0 dat
dst acc dat
mov acc x1
mov dat x1

Answer
9 9

1 Like

Thank you @Yatech !
If I try, in the test herebelow - please correct me!:
3
0 9 0
9
mov x0 acc → acc = 0
mov x0 dat → dat = 9
dst acc dat → acc = 90 dat = 9
dst 1 dat → acc = 990 dat = 9
dst 2 dat –>acc = 9900=>999 dat = 9
mov acc x1 print 999
mov x0 acc → acc=9990 =>999 dat=9
dst 2 dat –>acc=0999 dat=9
mov acc x1 print 999 Arrgh!no

My algorithm (which passed all tests :slight_smile:) does it the following way:

mov x0 acc // acc: 0, dat: 0
mov x0 dat // acc: 0, dat: 9
dst acc dat // acc: 9, dat: 9
dst 1 dat // acc: 99, dat: 9
dst 2 dat // acc: 999, dat: 9
mov acc x1 // acc: 999, dat: 9
mov x0 acc // acc: 0, dat: 9
dst 2 dat // acc: 900, dat: 9
mov acc x1 // acc: 900, dat: 9

Output: 999 900

1 Like

THANK ! YOU !
@Yatech : you saved me :slight_smile:
score = 100%

1 Like

Quite a fun challenge, enjoyed it.

1 Like

Hi, seems to have many errors in the statement :

MCxxxx Language official documentation : https://usermanual.wiki/Document/SHENZHENIOManual.736522646/view

=> the link doesn’t work

  • not : If the value in acc is 0, store a value of 100 in acc. Otherwise, store a value of

=> the end of the sentence is missing

| acc | Instruction | acc’ |
| 596 | dst 0 7 | 597 |
| 596 | dst 1 7 | 576 |
| 596 | dst 2 7 | 796 |

=> shouldn’t it be the opposite ? like | 596 | dst 0 7 | 796 | and | 596 | dst 2 7 | 597 |

  • tcp R/I R/I : Compare the value of the first operand with the value of the of the second operand

=> “of the” is in double

Thanks

1 Like

596 is a number, least significant digit’s place is on the right

End of line not wrapped somehow. Drag Statement<->Code vertical divider to the right

1 Like

Hi,

My code passes all of the provided tests, but when I submit, the test “Labels, jumps and unnecessary text (Validator)” fails. Do you have any idea of the differences between the normal test and the validator test?

BTW, this was fun to code.

1 Like

You’re right, thanks for the clarifications

Very enjoyable way to learn the basics of an “assembly like” language !

2 Likes

I took a look to the validator
try the following input (it is the same as test but with another comment altmost similar to validator one) :

1
2
11
mov x0 dat
mov dat acc
# mov acc dat ... useless (â•ŻÂ°â–ĄÂ°ïŒ‰â•Żïž” ┻━┻ ///
jmp end
mov dat x1
mult:
mul dat
jmp ending
end: jmp mult
ending:
mov acc x1

Expected result :

4
3 Likes

Thanks @b0n5a1, but my code works well on your example, I get the expected result. I remove everything after a # in a line of code, whatever is following the #. I don’t think the problem is about comment (but maybe). And I don’t see any problem in my jmp management (and my program works well on other validators). I don’t have any idea of what’s not working


I am not able to understand why on the 10th test case called “Overflow !!!”, the result should remain -999 and 999 as if both the subtraction and the addition should not be effective.

The instruction of the test case is:

  1. “mov x0 acc” ==> “Put the next input in acc” so the “acc” becomes “-999”

  2. “sub 50” ==> “Subtract 50 from the acc and store it to acc”, so -999 - 50 = -1049 which is the new “acc” value

  3. “mov acc x1” ==> “Output the acc”, so my 1st output is -1049 and not -999 which is the expected one

What am I missing ?

Instruction says:

Registers can store integer values between -999 and 999, inclusive. If an arithmetic operation would produce a result outside this range, the closest allowed value is stored instead. For example, if acc contains the value 800 and the instruction add 400 is executed, then the value 999 will be stored in acc.

1 Like

I really missed all that part. Thanks a lot

Hi all !
Fun exercise, but i’m stuck on the 13th validation test (not IDE tests but submission tests) that keeps failing while all IDE tests are green ; quite frustrating since i have no idea what can go wrong :-/
If someone could provide a test similar as the validator’s one, without spoiling the real one, i would be very grateful :slightly_smiling_face:
Thanks !

Ok, found my mistake, it was a stupid error in tcp implementation, that inverted results flags for greater and equal cases.
Thus, the IDE tests seems insufficient, since they allow validation with such a huge error.

I would suggest to replace the 13 test by something like below, inserting static outputs between tests to ensures that the rigth values are generated by the right tests :

1
0
12
mov x0 dat
tcp dat -1
+ mov 1 x1
- mov -1 x1
tcp dat 0
mov 5 x1
+ mov 1 x1
- mov -1 x1
tcp dat 1
mov 5 x1
+ mov 1 x1
- mov -1 x1

with expected output

1 5 5 -1

OK, try this one :

1
7
10
# Hello
jmp test
mov acc dat
another_test:
add 10
jmp hello
test:
mov x0 acc
jmp another_test
hello: mov acc x1

Expected result :

17
3 Likes