Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
259 views
in Technique[技术] by (71.8m points)

MIPS assembly - Label value modification

Is it possible in MIPS to change during execution the value of a label, or to create a label with certain value?

I ask this because when using the instruction lw $a0, label($s0) i want to increment the value of label +4 every time we loop, indicating the new memory address of the array. I am aware I can do lw $a0, label+4($s0) but the new value of label will not be stored.

Any advise?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

No. In MIPS you must have a constant outside the parentheses when dereferencing (poor wording). If it were possible to change the value of the label, then it would no longer be constant. To get around this, you could instead do something like

la $t1, label          #t1 holds address of label
add $t1, $t1, $s0      #t1 now holds address of label + s0 offset
lw $a0, 0($t1)         #load word from t1's location

addi $t1, $t1, 4       #t1 was incremented by 4 bytes now
lw $a0, 0($t1)         #load the next word

It might be advisable to use addu if s0 will always be non-negative.

EDIT: You cannot change the value of a label. It is solely an alias for a location in memory. In the text section, it's an alias for the position of the following instruction. In the data section, it's an alias for the location in memory of the following space.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...