(ARM assembly) Shifting a register right 1 sets all bits to zero -


I think I am going crazy I am trying to write a function which is the hardware floating point in the ARM assembly Imitates. I have the function float simulate_fp_add (float, float) which currently looks like this:

  .global simulated_fp_add .type simulated_fp_add,% function simulated_fp_add: push {r3 , R4, R5, R6, LR} mov r0, r0, lsr # 1 pop {r3, r4, r5, r6, pc}   

My main file (simplified) Just calls my ARM function two floats arbitrarily and the result is in decimal and binary:

  #include & lt; Stdio.h & gt; Float simulate_ff_ed (float, float); Zero prt_bin (unsigned int, unsigned int); Int main () {float x, y, z; Unsigned int a, b, c; Association {float f; Unsigned int i; } U; X = 125; Y = 0.5; U.f = x; A = u.i; U.f = y; B = u; C = simulate_ff_ed (a, b); U.f = c; printf ("simulated_fp_add (% d,% d) =% f \ n", a, b, u.f); printf ("result in binary:"); Pret_bin (c, 32); Putchar ('\ n'); Return 0; } Zero prt_bin (unsigned int value, unsigned full length) {int i; For (i = (length -1); i> = 0; i--) {if ((value> i) & amp; 1) echo ('1'); And Puster ('0'); }}   

Output removed with shift line:

  simulated_fp_add (1123680256, 1056964608) = 125.000000 results in binary: 010000101111101000000000000000000000   

Output with transfer:

  simulated_fp_add (1123680256, 1056964608) = 0.000000 Results in binary: 000000000000000000000000000000000000   

All my simulated_fp_add function foil right In 1, but the result is zero? Am I missing something?

You have a combination of things that are working against you.

  Float simulated_ff_ed (float, float); C = simulate_ff_ed (a, b); U.f = c;   

You are calling a function that floats with the integer values ​​of the floating point bit pattern before they are being converted to the floating point value. Probably not with your intentions.

You are converting the return value of simulated_fp_add () to an unsigned int (c) and then to a float (uf).

Finally, simulated_fp_add () makes a logical change to a value that will be interpreted as the name. Its effect is unpredictable, but you are likely to give an unusual floating point value, which will fall from zero to the above integer conversion.

You should start by writing a very small piece of code, test it, and then start over with something like this:

  Unsigned difference changes ( Unsigned one A); Int main () {unsigned int a, c; A = 5; Printf ("a =% 0x \ n", a); C = shift (A); Printf ("c =% 0x \ n", c); Return 0; }    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -