assembly - Mips dynamic memory allocation and pointers -
i building compiler bison , encountered problem. need dynamically allocate memory , store string print content.
i thought saving pointer in data section allocating memory save address in pointer, assign string val print it. problem when trying print string prints first char. here code example.
.data p: .word 0 # pointer save allocated memory first address. .text li $v0,9 #allocate instruction li $a0,64 # allocate 64 byte syscall sw $v0,p #save first memory address pointer p li $t0,'a' #write first byte 'a' cahr sw $t0,0($v0) li $t0,'b' #write first byte 'a' cahr sw $t0,4($v0) li $v0,4 #print instruction lw $a0,p syscall
this result in char on mars console. ideas why?
i'm guessing: chars stored in bytes. b should go in 1($v0) not 4($v0) , you'll need null in 2 terminate.
Comments
Post a Comment