# [Community Puzzle] MCxxxx microcontroller simulation

Coding Games and Programming Challenges to Code Better

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
``````

`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 ) 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
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

• 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
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:
``````17