Results 1 to 8 of 8

Thread: How do u figure out the 16 bit offset of a branch? [Resovled]

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member voidflux's Avatar
    Join Date
    Jun 2003
    Location
    Brockway, PA
    Posts
    290

    How do u figure out the 16 bit offset of a branch? [Resovled]

    Hello everyone.

    I'm studying for my exam and i'm stuck on this problem..

    For the asm code given below, what is the value of the 16-bit offset in the instruction 'beq'
    beq $t0, $t1, label
    sub $t2, $t0, $t1
    addi $t2, $t2, 4
    sw $t2, 0($s0)
    label:.....

    the answer is 0x0010, I thought u start counting from the beq instruction but yesterday the profesor showed me on the sample test and she said u don't start counting at beq, but right after beq, so u would count down till u get to the label:...


    This would make sense to me if u start counting at beq, then it would be
    0
    4
    8
    12
    16

    if u convert 16 from decimal to hex u get 10, so is that how they got 0x0010 ?


    But the professor explained this problem to me which doesn't follow that pattern:

    loop: beq $s0, $s2, exit
    add $s0, $s0, $s1
    j loop
    exit: lui $s0, 48

    whats the machine code?
    answer:
    beq [4][16][18][2]

    2 is the 16 bit offest in this case, i asked her how did u get 2?
    well she said, u start one right after the branch instruction and start counting...
    so if u did that, u would count
    0
    4
    8 and at 8, u would hit the label exit:
    she said they got 2 because ur jumping 2 words, so its 2.

    can anyone help me out?
    Last edited by voidflux; Oct 9th, 2006 at 12:35 PM.
    C¤ry Sanchez
    Computer Science/Engineering
    @ Penn State
    IBM.zSeries Intern
    Mandriva 2007

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width