To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
Part 10 of the Visual Basic .NET 2010 Express Tutorial Complete!
How to Use the Visual Studio Code Analysis Tool FxCop
Article :: Interview with Andrei Alexandrescu (Part 3 of 3)
Introducing Visual Studio LightSwitch
Visual Studio LightSwitch Beta 1 is Available



Go Back   VBForums > Other Languages > Assembly

Reply Post New Thread
 
Thread Tools Display Modes
Old Oct 8th, 2006, 10:09 PM   #1
voidflux
Hyperactive Member
 
voidflux's Avatar
 
Join Date: Jun 03
Location: Brockway, PA
Posts: 290
voidflux is an unknown quantity at this point (<10)
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?
__________________
C¤ry Sanchez
Computer Science/Engineering
@ Penn State
IBM.zSeries Intern
Mandriva 2007

Last edited by voidflux; Oct 9th, 2006 at 12:35 PM.
voidflux is offline   Reply With Quote
Old Oct 9th, 2006, 11:03 AM   #2
CornedBee
Kitten
 
CornedBee's Avatar
 
Join Date: Aug 01
Location: In a microchip!
Posts: 11,594
CornedBee is a glorious beacon of light (400+)CornedBee is a glorious beacon of light (400+)CornedBee is a glorious beacon of light (400+)CornedBee is a glorious beacon of light (400+)CornedBee is a glorious beacon of light (400+)CornedBee is a glorious beacon of light (400+)
Re: How do u figure out the 16 bit offset of a branch?

Well, it's exactly as she said. The byte offset is the number of instructions * 4. But in the machine code, the word offset (i.e. the instructoin count) is stored, not the byte offset.

Be glad you've got a fixed-size instruction set here
__________________
All the buzzt
CornedBee

"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen

Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
CornedBee is offline   Reply With Quote
Old Oct 9th, 2006, 11:27 AM   #3
voidflux
Hyperactive Member
 
voidflux's Avatar
 
Join Date: Jun 03
Location: Brockway, PA
Posts: 290
voidflux is an unknown quantity at this point (<10)
Re: How do u figure out the 16 bit offset of a branch?

Thanks for the responce!

So for
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:.....

So if she wants the 16 bit offset, and the chocies are the following:
A. 0x0010
B. 0x0004
C. 0x0003
D. 0x000c

when u say instruction count do u mean, like:

0 beq $t0, $t1, label
1 sub $t2, $t0, $t1
2 addi $t2, $t2, 4
3 sw $t2, 0($s0)
4 label:.....

so if u start counting at Program counter + 4, meaning the line right after you encounter the beq, you would get, 4 words away until you hit label:...
but I don't see how that equals 0x0010.

If you break it into just looking at the words you would count by 4's and get:
0 beq $t0, $t1, label
4 sub $t2, $t0, $t1
8 addi $t2, $t2, 4
12 sw $t2, 0($s0)
16 label:.....

and if u started counting at sub $t2 by 4's you would get, 12 until you hit label:....

thanks!
__________________
C¤ry Sanchez
Computer Science/Engineering
@ Penn State
IBM.zSeries Intern
Mandriva 2007
voidflux is offline   Reply With Quote
Old Oct 9th, 2006, 11:35 AM   #4
CornedBee
Kitten
 
CornedBee's Avatar
 
Join Date: Aug 01
Location: In a microchip!
Posts: 11,594
CornedBee is a glorious beacon of light (400+)CornedBee is a glorious beacon of light (400+)CornedBee is a glorious beacon of light (400+)CornedBee is a glorious beacon of light (400+)CornedBee is a glorious beacon of light (400+)CornedBee is a glorious beacon of light (400+)
Re: How do u figure out the 16 bit offset of a branch?

You're still counting the branch instruction itself. Don't. From the beq to the label it's three instructions (sub, addi, sw), i.e. three words, 12 (0xC) bytes.

If you want to know which you have to specify at the test, you'd best ask her.
__________________
All the buzzt
CornedBee

"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen

Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
CornedBee is offline   Reply With Quote
Old Oct 9th, 2006, 11:55 AM   #5
voidflux
Hyperactive Member
 
voidflux's Avatar
 
Join Date: Jun 03
Location: Brockway, PA
Posts: 290
voidflux is an unknown quantity at this point (<10)
Re: How do u figure out the 16 bit offset of a branch?

Ahh i got you now! its 3 words like you said or 3*4 = 12 and in hex it would be 0xC. But on the quiz the answer was 0x0010 but there was a choiice of 0x000C, do you think there was an error on the quiz (there are lots) and the answer should have been 0x000C?
__________________
C¤ry Sanchez
Computer Science/Engineering
@ Penn State
IBM.zSeries Intern
Mandriva 2007
voidflux is offline   Reply With Quote
Old Oct 9th, 2006, 12:06 PM   #6
CornedBee
Kitten
 
CornedBee's Avatar
 
Join Date: Aug 01
Location: In a microchip!
Posts: 11,594
CornedBee is a glorious beacon of light (400+)CornedBee is a glorious beacon of light (400+)CornedBee is a glorious beacon of light (400+)CornedBee is a glorious beacon of light (400+)CornedBee is a glorious beacon of light (400+)CornedBee is a glorious beacon of light (400+)
Re: How do u figure out the 16 bit offset of a branch?

From all you've said, I'm pretty sure.
__________________
All the buzzt
CornedBee

"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen

Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
CornedBee is offline   Reply With Quote
Old Oct 9th, 2006, 12:32 PM   #7
voidflux
Hyperactive Member
 
voidflux's Avatar
 
Join Date: Jun 03
Location: Brockway, PA
Posts: 290
voidflux is an unknown quantity at this point (<10)
Re: How do u figure out the 16 bit offset of a branch?

Thanks! i'll ask her about it tomarrow
__________________
C¤ry Sanchez
Computer Science/Engineering
@ Penn State
IBM.zSeries Intern
Mandriva 2007
voidflux is offline   Reply With Quote
Old Oct 10th, 2006, 09:03 PM   #8
voidflux
Hyperactive Member
 
voidflux's Avatar
 
Join Date: Jun 03
Location: Brockway, PA
Posts: 290
voidflux is an unknown quantity at this point (<10)
Re: How do u figure out the 16 bit offset of a branch? [Resovled]

She said hte correct answer is:
C. 0x0003
because its 3 "words" away
or u can write out the binary because its 4*3 bytes away, and chop of the lower 2 order bits and also the high order 4 bits and then regroup and you'll come out with x0003
__________________
C¤ry Sanchez
Computer Science/Engineering
@ Penn State
IBM.zSeries Intern
Mandriva 2007
voidflux is offline   Reply With Quote
Reply

Go Back   VBForums > Other Languages > Assembly


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 05:15 AM.





Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.