MIC IJVM simple sum of 2 digits

陌路散爱 提交于 2019-12-24 18:43:53

问题


just a simple question regarding calculations in IJVM as I couldn't find the solution in their documentation.

Suppose we need to perform the following calculation:

BIPUSH 0x32 // PUSH 2
BIPUSH 0x33 // PUSH 3
IADD // PUSH sum(2,3)
OUT // output: "e"

IADD ----> Pop two words from stack; push their sum

I know the solution is likely straight forward, but for the life of me I can't recall on how to convert the addition/output to the actual digits. How to make it output "5" instead of this stupid "e"? :)

Cheers.


回答1:


As expected, the answer to this problem was very simple. That's very much contradictory to actually finding the answer as no one seem to bother to mention this anywhere in the docs. Awesome.

Solution:

BIPUSH 0x32 // PUSH 2
BIPUSH 0x33 // PUSH 3
IADD // PUSH sum(2,3)
DUP
BIPUSH 0x30 // PUSH 0
ISUB // subtract 0
OUT 

Or the actual code:

plus:
    ILOAD X
    ILOAD Y
    IADD
    DUP
    BIPUSH 0x30
    ISUB
    GOTO return // Dominykas Tautkus. Linkėjimai prodekanui. :)

Subtracting 0 after performing addition forces it to treat this as an actual mathematical task with integers so to speak.



来源:https://stackoverflow.com/questions/48131680/mic-ijvm-simple-sum-of-2-digits

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!