First of all, hi to everyone.
I need help with an assignment, need to translate this C code to assembly. im getting pretty desperate and thats why im turning to outside help...
This code is suposed to calculate sqare roots of 16bit numbers, and is to be implemented on another code as a subroutine. Needs to work on a pedagogical processor. The value to be calculeted comes from the stack pile.
hope i can get some help here!!!

;   short sqrt(short num) {
;        short op = num;
;        short res = 0;
;        short one = 1 << 14; // The second-to-top bit is set: 1L<<30 for long
; 
;        // "one" starts at the highest power of four <= the argument.
;        while (one > op)
;            one >>= 2;
; 
;        while (one != 0) {
;            if (op >= res + one) {
;                op -= res + one;
;                res += one << 1;
;            }
;            res >>= 1;
;            one >>= 2;
;        }
;        return res;
;    }

thx for bothering to read :)
cheers

Recommended Answers

All 4 Replies

What have you done so far?

PS: I am a psychic, but even I cannot tell the instruction set of

a pedagogical processor

Thx for your reply mate, ill pm you what i have made so far.

Any other experienced coder willing to help me? Time is running out :|
I have the manual for that processor, i just dont wanna make my code public so that other colleague of mine doesnt copy it and we both get a 0...

gcc -S prog.c
Will generate some asm.

Try cribbing from that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.