Close

Math demo program

A project log for L1VM

A tiny virtual machine with a 64 bit RISC CPU.

jay-tjay-t 03/29/2022 at 19:012 Comments
// math-lib.l1com
// math library demo
// 
#include <math-const.l1h>
#include <intr.l1h>
(main func)
    (set int64 1 zero 0)
    (set int64 1 randstart 2003)
    (set int64 1 random 0)
    (set int64 1 digits 3)
    (set int64 1 numstr_len 30)
    (set int64 1 not_num 0)
    (set int64 1 not_ret)
    (set string 30 numstr "")
    (zero :math_init call)
    (loadreg)
    (randstart :math_randinit call)
    (loadreg)
    (:math_randint call)
    (random stpopi)
    (loadreg)
    print_i (random)
    print_n
    print_d (m_pi@math)
    print_n
    // round pi to "digits" (3) digits and store number in string
    (m_pi@math digits numstraddr numstr_len :double_rounded_string call)
    (loadreg)
    print_s (numstr)
    print_n
    (not_num :math_not call)
    (not_ret stpopi)
    (loadreg)
    print_i (not_ret)
    print_n
    // close module
    free_mod (zero)
    exit (zero)
(funcend)
#include <math-lib.l1h>

This demo program prints out:

$ l1vm lib/math-lib -q
3368910609462220170
3.1415926536
3.142
1

Discussions

jay-t wrote 03/19/2024 at 23:51 point

What do you want to know?

  Are you sure? yes | no

fersadilala wrote 03/18/2024 at 22:04 point

I didn't understand much about how you did it. I still have a lot of questions in my head. In college, I just asked do my math homework, I found https://edubirdie.com/do-my-math-homework for myself. Therefore, I never had any problems. But now it’s just some kind of trouble. I would be grateful if you could explain the logic of the task.

  Are you sure? yes | no