assembly - Error where it shouldnt mips -


can please tell me why have errors in this?? error says unaligned address @ sdc1. seems pretty me. rest of code?

la $a1,  #ask a(1,1) li  $v0 , 4 la  $a0 , a11        syscall  #read double li  $v0 , 7 syscall  #store double sdc1    $f0 , ($a1) 

i'm not mips expert, iirc, 2 things should you:

1)

a0-a3 "argument" registers, may modified sub-calls according calling convention, don't want store there pointer value use on longer period.

for registers s0-s7 better, should preserved routine, i.e. own code should first store them on stack example (and restore them original value before returning), before modifying hold a1 address, syscall or correctly written sub-routine should keep s? value preserved.

if have piece of code, doesn't call anything, may use t0-t7 registers temporary values, can modify freely (or a0-a3, subroutine may modify argument values).

2)

sdc1 instruction needs address 8-byte aligned (lowest 3 bits zeroed).

if have dynamically allocated memory heap, unsure it's alignment, allocate +8 bytes more, , adjust pointer of allocated memory ((ptr+7)&(-8)), clear lowest 3 bits (also keep around original pointer value, need deallocate memory). used aligned value start of buffer double values.


just make sure understand meant "alignment". computer address "aligned" 2/4/8/... bytes, if value can divided number without remainder. address 800 8-byte aligned (800/8 = 100), 804 not 8-byte aligned (804/8 = 100.5). alignment of power of 2 required in computers, , values binary encoded in bits, there's no need actual division of value verify it's alignment. binary encoding number of cleared lowest bits defines it's alignment powers of two. no clear bit = odd number (aligned 1 only), lowest bit clear = number (aligned 2), 2 bits clear = divisible 4 = aligned 4. 8 byte alignment bottom 3 bits has zero. if have address in hexadecimal formatting, last digit must either 0 or 8 (0000 or 1000 in binary). other hexadecimal digit has bit set in lowest three, i.e. such address not divisible 8, it's not aligned sdc1 instruction.

so if understand paragraph above, can check if address valid in debugger, seeing value in register in hexadecimal formatting (almost every debugger shows values in hexadecimal default, makes easy human see particular bits , bytes, in decimal formatting have calculate remainder of division 8 sure).

as how define a array in aligned way... didn't show how define it, it's hard tell. let's guess use 1 of mars/spim mips emulators these exercises. can allocate 800 bytes aligned 8-byte boundary code:

        .align 3      # align next data item 2^3 (= 8) boundary array:  .space 800    # allocate 800 bytes of space 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -