0

So I've been learning about machine code and assembly language the past few weeks but am somewhat struggling. One of the problems on my assignment asks to convert the listed sequence below into assembly language but I'm just not understanding where to start. Nothing within our notes looks even close to this problem and the textbook isn't much help either. Here's the information given to me:

F(0) = 1;
M(0) = 0;
F(n) = n – M(F(n – 1)) when n > 0
M(n) = n – F(M(n – 1)) when n > 0

I'm pretty much lost at this point as everything we've been doing up until this question has been converting if and while loops along with some array comparisons. Can anyone guide me in the right direction?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • 1
    You might try transcribing this into C from this more-or-less mathematical notation. Taking this intermediate step will help you get further along and see where you are really stuck (math notation ==> C or C ==> assembly). – Erik Eidt Oct 02 '19 at 21:10
  • The definition is mutually-recursive with 2 functions that call each other as well as being self-recursive. Presumably you've been taught how to write a function that calls another function. Or it can probably simplify into something iterative if you want, though, unless the assignment requires you to implement it with mutual recursion. – Peter Cordes Oct 03 '19 at 04:29
  • I was curious to see if GCC or clang could optimize it down to iterative. gcc9.2 does partially inline them into each other, but basically goes berserk and emits over 6000 lines of asm. https://godbolt.org/z/E7N6j- (I compiled for x86 because Godbolt's MIPS GCC install is only gcc5.4). Clang just makes normal asm that basically compiles as written without trying to inline or optimize to iterative. – Peter Cordes Oct 03 '19 at 04:40

0 Answers0