1

I have an assignment to do but all of the topics have not been thoroughly discussed in class. We are coding in assembly (SPARC). This is the assignment:

Write an assembly program to test if the flag 0x10 is set in the register %l0. If it is set, then multiply the content of %l0 by 2 using the appropriate shift instruction and exit immediately. If it is not set, then divide the content of %l0 by 2 using the appropriate shift instruction and exit. You may test your program when %l0 is equal to 0x18 and when %l0 is equal to 0x08.

This is the code I have so far:

.global main

main:
    save    %sp,-96,%sp
    clr     %l0
    clr     %l1
    mov     0x10,%l1
    btst    0x10,%l0        !Test if a bit/s clear or set
    be      clear           !Goto
    nop
set:
    sll     %l1,1,%l3       !shift %l0 left (%l0*2)
    ba      exit
clear:
    srl     %l1,1,%l3       !shift %l0 right (%l0/2)
    ba      exit
exit:
    mov     1,%g1           !Exit
    ta      0

What does set and clear mean? When using btst, what occurs? What is the correct format for best? Are my shift left and shift right(to multiply and divide) done correctly?

I have tried to look through the site and google as well, however I cannot come up with any thorough explanation for this.

thank you

boydf
  • 7
  • 3

0 Answers0