intel - Anyone understand what these instructions are asking, and know how to write this in assembly? -


problem- using intel86 simulator, given 3 one-byte numbers x, y , z (1<x,y,z<100), write code computes modular exponentiation x^y mod z (example, x=4, y=3, z=5 result = 4). x, y , z found in memory positions 107h, 108h , 109h of program, make sure not use bytes instructions. result of calculation should must stored in dl.the algorithm code used compute modular exponentiation x^y mod z is: d,1. assume y represented bits yk,yk-1,yk-2,...y0 j <-- k down 0 d <-- (dd) % z if y1 == 1 d <-- (dx) % z result in d.

seems algorithm poorly worded, , backwards, assuming goal repeatedly square x mod z speed process.

    r = 1;     goto loop1; loop0:      if(y & 1) /* if least signficant bit of y set */         r = (r * x) % z;     x = (x * x) % z     y = (y >> 1) /* logical (unsigned) shift right) */ loop1:     if(y != 0)         goto loop0;     dl = r;