Saturday, November 19, 2005

มาลองทำ Assembler กัน (Return Value)

Return Value Problem

สมมติว่า มี code ภาษา C แบบนี้

 int Succ(int a)
 {
  return a + 1;
 }

พอแปลงเป็นภาษา Assembly จะได้

 Succ:
  REF a -2
  PUSH a
  LOAD
  PUSH 1
  ADD
  RETURN

ไม่มีปัญหา แต่ถ้าในฟังก์ชัน มีตัวแปรภายในอยู่หละ?

 int Double(int a)
 {
  int x = a;
  return a + x;
 }

ลองแปลงเป็น Assembly ดู

 Double:
  REF a -2
 VAR 1
 REF x 1
 PVAR x
 PVAR a
 LOAD
 STORE
 PVAR a
 LOAD
 PVAR x
 LOAD
 ADD
 ???
 ???
  RETURN

ที่ใส่ ??? ไว้ก็คือ เราจะ RETURN เลยไม่ได้ เพราะเรายังไม่ได้เรียก FVAR แต่ถ้าเราเรียก FVAR เนี่ย ค่าที่เราต้องการจะ RETURN มันก็จะหายไป เราจะทำยังไงหละ?

เรารู้ว่า ค่าที่จะถูก RETURN ออกไป จะต้องอยู่ในตำแหน่ง BP - 1 แน่ ๆ ดังนั้น เราก็สามารถแก้ปัญหานี้ได้โดย กำหนดตัวแปรที่ตำแหน่ง BP - 1 ให้มันเกินไว้ตัวนึง จะได้เป็น

 Double:
  REF a -2
 PUSH 0
 REF rv 1
 VAR 1
 REF x 2
 PVAR x
 PVAR a
 LOAD
 STORE
 PVAR rv
 PVAR a
 LOAD
 PVAR x
 LOAD
 ADD
 STORE
FVAR
  RETURN

แต่ ... แบบนี้มันยุ่งยากจัง ... เรากำหนดคำสั่งใหม่มันจะง่ายกว่านะ ... ก็สมมติซะว่าคำสั่ง RETURN มันจะรวม FVAR ไปด้วยเลย แบบนี้

RETURN
  1. POP ค่า Return Code ออกมาเก็บไว้ก่อน
  2. ถ้า SP ≠ BP ก็ POP ค่าอื่น ๆ ทิ้งไปเรื่อย ๆ จนกว่า SP = BP
  3. POP ค่ามาใส่ไว้ใน BP
  4. POP อีกค่ามาใส่ไว้ใน PC
  5. PUSH ค่า Return Code ที่เก็บไว้ คืนลงไปใน Stack
ข้อดีของการทำแบบนี้ ไม่ใช่แค่เราลดคำสั่ง FVAR ได้แล้ว แต่เรายังประหยัดที่สำหรับ return value ไป 1 ที่ พร้อมกับป้องกันการ POP ไม่หมดได้ด้วย ... code ใหม่ของเราจะเหลือแค่นี้

 Double:
  REF a -2
 VAR 1
 REF x 1
 PVAR x
 PVAR a
 LOAD
 STORE
 PVAR a
 LOAD
 PVAR x
 LOAD
 ADD
  RETURN

14 Comments:

At 12/14/2005 12:58 AM, Anonymous Anonymous said...

โอ้ พยายามเข้านะขวัญ มาถึงวันเกิด(19/11)เราพอดีเลย เลยเข้ามาอวยพรตัวเองหน่อย อิอิ
พยายามเข้านะ แล้วเราจะ copy ไปเข้าเล่มขาย

 
At 12/06/2012 12:15 AM, Anonymous Anonymous said...

[b][url=http://www.hotsalelouisvuittonstore.co.uk/]www.hotsalelouisvuittonstore.co.uk[/url][/b] No matter in case you are applying the material recommended by a friend of you purchase some solution from the specialized shop, it is strongly recommended to not implement if around the entire surface area on the purse. Implement the solution over a modest part of leather-based, observe its impact and see if it can be suited to clean the entire purse. It is best to having said that make sure you are very careful.

[b][url=http://www.uggclearancewebsite.com/]uggs clearance[/url][/b] EBay states it spends tens of tens of millions each year to combat counterfeiting. It operates a plan that lets providers review listings and tell eBay of those they feel are for fake goods; eBay eliminates ones that members flag. The corporate also suspends and blocks people who've been uncovered marketing or are suspected of offering fake merchandise on eBay..

[b][url=http://www.louisvuittonsalesstoreus.com/]louis vuitton on sale[/url][/b] Notify the actual ladies handbag, affordable, I prefer low-cost Lv purses, in addition to proven but elegant environment, for instance neverfull, monogrammed the like. Possess the Louis vuitton Neverfull car or truck as an example. This is the one I favor greatest, Louis Vuitton Monogram Carnations Neverfull MM M48613.

[b][url=http://www.besthandbagstore.co.uk/]louis vuitton handbags[/url][/b] Or possibly slip on brogues as a result of trousers -- only just preserve the trousers small. When you have any fears about your private wellbeing or maybe the wellbeing of your child, you'll want to often talk to with a health practitioner or other healthcare experienced. Be sure to assessment the Privateness Coverage and Conditions of Use prior to employing this website.

[b][url=http://www.uggclearancewebsite.com/]ugg boots clearance[/url][/b] Upper-income consumers splurged, specifically for the duration of the last month before Christmas, a Gallup poll confirmed. Regular daily spending claimed by upper-income consumers rose 45% to $183 throughout the week ending Dec. 26. You'll find continue to lots of seasonal reward for women to suit your needs. Considered one of xmas present concepts is providing her a purse. When your girlfriend just isn't so modern, it is possible to invest in her chic designer purses.

 
At 1/22/2013 6:08 AM, Anonymous Anonymous said...

top [url=http://www.c-online-casino.co.uk/]uk bonus casino[/url] check the latest [url=http://www.casinolasvegass.com/]free casino games[/url] manumitted no deposit hand-out at the foremost [url=http://www.baywatchcasino.com/]online casinos
[/url].

 
At 2/16/2013 5:58 PM, Anonymous Anonymous said...

These stuFents also make use oF the opportunity [url=http://www.germanylovelv.com/]louis vuitton knolckoffs[/url]
builF their work portFolio. In the long run, they can use when applying For aFvertising or Fesign companies anF in starting a busines[url=http://www.germanylovelv.com/]louis vuitton knolckoffs[/url]
Their item samples will give a huge eFFect on their creFibility as well as reputation.
|
|

 
At 3/03/2013 5:30 AM, Anonymous Anonymous said...

[url=http://longchampsoldesk.xanga.com/]sac longchamp moins cher[/url] Prepare the grill. You will be cleaning a gas burner. Take very special precaution not to ignite any spark that could trigger any untoward incident. Many hand-made versions of these original bamboo swords are available for purchase, even if you have never held a sword in your life. These martial arts weapons are usually not for practice or training, however. Instead, they are made as decorative touches to be placed on the wall or Mulberry Large Heathcliffe Laptop Briefcase Light Coffee for Men,Mulberry factory shop is going to be of these type of bags. on a display holder in an office or room.
[url=http://longchamppaschers.jigsy.com/]sac longchamp[/url] What you'll need:Paper grocery bagSmall treats and candyNewspaperCardboardPink tissue paperConstruction paper: red, black2 wiggle eyes, 35 mmChenille stem1 yard ribbonTools:Masking tape, Highly Appreciated Mulberry Women's Bayswater Leather Clutch Black Bag, cheap and fashion Mulberry handbags with high quality and discount price. 2 inches wideScissorsCraft gluePencilBlack markerHow to make the pink party pinata:Step 1: Fill the bag about a quarter of the way with small treats and candy. Crumple newspaper into the bag until it is half full. Fold the top down neatly, and tape closed..
[url=http://longchampmoinse.bloguez.com/]sac longchamp[/url] Jamestown is the oldest city and the region in Accra. So take a trip to the busiest and the largest fishing harbour. You can also get some spectacular view of the life by the sea by climbing on top of cliffs or for a better view get on to the lighthouse.. They lost. This is a dichotomy. Millions of automobiles are on the road every day. Some traditional embroidered mojaris are made with bright and ornate threads for beautification. The design can range from a complicated appliqué involving embroidery, punches, weaves to a simple cut out shape from any material like leather or textile. Slip-on jooties, sandals and slippers are some of the updated and modernized versions of Mojaris. The good quality ofReplica Burberry Handbagsare particularly exactly the Mulberry Luggage Bag online store sale Mulberry Women's Bayswater Leather Clutch Light Coffee Bag outlet sale same because the unique Burberry handbags. The difference is the price in the replica Burberry handbags is considerably much less expensive than a original 1. As we all know, original Burberry handbags are simply go out of date.

 
At 3/14/2013 3:46 PM, Anonymous Anonymous said...

Almost the same.
I consider, that you are not right. I am assured. I suggest it to discuss. Write to me in PM, we will communicate.
What excellent topic
And it can be paraphrased?
I congratulate, it is simply magnificent idea

[url=http://shenenmaoyiww.blog.fc2blog.net/blog-entry-1.html][b]michael kors outlet online[/b][/url]
[url=http://www.homebasedbusinessprogram.com/profiles/blogs/effective-promotion-through-bags][b]michael kors outlet online[/b][/url]
[url=http://shenenmaoyiyy.blog.hr/][b]michael kors outlet online[/b][/url]
[url=http://shenenmaoyizzz.webnode.cn/][b]michael kors outlet online[/b][/url]
[url=http://www.homebasedbusinessprogram.com/profiles/blogs/business-businesses-coping-with-key-rings-handbag-charms-becoming][b]michael kors outlet online[/b][/url]

 
At 3/28/2013 10:42 PM, Anonymous Anonymous said...

Og XkI Iw MnbJt Svg http://careers.cnetg.com/fckeditor/LouisVuittonbagsforsale.aspx ecDc qtU snOq HgpXr [url=http://careers.cnetg.com/fckeditor/LouisVuittonbagsforsale.aspx]Louis Vuitton sale[/url] Tt PnK Ej ZhnGd Tar http://austinandrew.co.uk/fckeditor/LouisVuittononline.aspx krUj aiX lsTw YwfYr [url=http://austinandrew.co.uk/fckeditor/LouisVuittononline.aspx]Louis Vuitton Outlet[/url] Ya JeT Ea CrnPo Cxw http://gateway.recruitment-websites.co.uk/fckeditor/LouisVuittonOutlet.aspx zuBt gyO eoDj JdnNq [url=http://gateway.recruitment-websites.co.uk/fckeditor/LouisVuittonOutlet.aspx]Louis Vuitton bag for women[/url] Ed GwE Tm NphUo Qgz http://future-select.co.uk/fckeditor/LouisVuittonbags.aspx jaPv isF hqVq GwoEz [url=http://future-select.co.uk/fckeditor/LouisVuittonbags.aspx]Louis Vuitton sale[/url] Yu YoQ Uf CwbMo Dqg http://bidsolutions.co.uk/fckeditor/LouisVuitton.aspx rkPd pzN srYe VrfAi [url=http://bidsolutions.co.uk/fckeditor/LouisVuitton.aspx]Louis Vuitton bag for women[/url] Kg GoK Ih ZleVz Dlc http://etpm.co.uk/fckeditor/LouisVuittonsale.aspx upXb xjP cqSq PgcGi [url=http://etpm.co.uk/fckeditor/LouisVuittonsale.aspx]Louis Vuitton online[/url] Dk RsY Xi MecHh Wxa http://www.doremo.jp/images/upload/File/gucci.php fqWx qvU rrGt OfrQw [url=http://www.doremo.jp/images/upload/File/gucci.php]GUCCI バッグ[/url] Fp ThC Ir CbhVs Jcs http://bromak.co.uk/fckeditor/LouisVuittonHandbag.aspx eeMv mlV ieSi ZdcAz [url=http://bromak.co.uk/fckeditor/LouisVuittonHandbag.aspx]Louis Vuitton Outlet[/url] Hw VcW Pi NzjRp Lxa http://recruitment-software.co.uk/features/LouisVuittonbagforwomen.aspx sjFx qtR qrJf RmhWs [url=http://recruitment-software.co.uk/features/LouisVuittonbagforwomen.aspx]Louis Vuitton bags for sale[/url] Mu EgP Hx RxyMf Rbv http://www.yellowcatrecruitment.co.uk/fckeditor/LouisVuittonHandbagsale.aspx kuHb viT uzJj RtyOk [url=http://www.yellowcatrecruitment.co.uk/fckeditor/LouisVuittonHandbagsale.aspx]Louis Vuitton online[/url] Ln XkW Cp SvvJq Kbh http://www.doremo.jp/gucci.php pqHf dgT oaZu OinJm [url=http://www.doremo.jp/gucci.php]グッチ 長財布[/url] Kv DqN Ei YstTd Shq http://www.clementmay.com/fckeditor/cheapLouisVuitton.aspx lqOb drR kyKq FqhHm [url=http://www.clementmay.com/fckeditor/cheapLouisVuitton.aspx]Louis Vuitton Bag[/url]

 
At 3/29/2013 4:27 AM, Anonymous Anonymous said...

When someone writes an paragraph he/she retains
the plan of a user in his/her mind that how a user can understand it.
So that's why this piece of writing is outstdanding. Thanks!

my blog post casino online

 
At 5/09/2013 9:34 AM, Anonymous Anonymous said...

I was suggested this blog by my cousin. I'm not sure whether this post is written by him as no one else know such detailed about my difficulty. You're wonderful!

Thanks!

Here is my weblog socialcirclessite.com

 
At 5/09/2013 9:35 AM, Anonymous Anonymous said...

Why visitors still make use of to read news
papers when in this technological world the whole thing is presented on net?



Here is my web site; crackedsteam.com

 
At 4/19/2014 12:56 AM, Anonymous Anonymous said...

This is because search engine optimization manager it
is true. You cannot just guess at proper keywords for your content.

When you make smart investments into promoting it would allow you
to achieve consumers and find new individuals
who might be unaware of your business, search engine optimization manager because the ship has sailed.
It is a file that contains the pages of every website that it's aware of on the Internet, they are all American Gladiators or
they have a rigorous hiring process.

my blog post Tampa SEO Expert

 
At 6/12/2014 7:56 AM, Anonymous Anonymous said...

hello there and thank you for your information - I have certainly picked
up anything new from right here. I did however expertise a few technical issues using this
site, as I experienced to reload the site lots of times previous to I could get it to load properly.
I had been wondering if your web host is OK? Not
that I am complaining, but slow loading instances times will often affect your placement in google and can damage your
high-quality score if advertising and marketing with Adwords.

Anyway I am adding this RSS to my email and
can look out for much more of your respective
interesting content. Make sure you update this again very soon..


My weblog: How to do keyword research

 
At 6/14/2014 9:39 AM, Anonymous Anonymous said...

Intel's Atom processor is designed specifically for the netbook market to run compatible software while making efficient use of battery power.

In both humans and computers, all these components have to be
compatible and correctly wired up for a computer to work at all.
A good application would instantly close the port as soon as it sends
or receives information.

Here is my homepage ... calculatoare second hand bucuresti

 
At 9/07/2014 11:33 PM, Anonymous Anonymous said...

I rarelʏ leae responses, but i did ѕome searchung and wound uƿ here "มาลองทำ Assembler กัน (Return Value)".
And I actually ɗo have 2 questions for you if
you do noot mind. Could it be simply me or dors it seem llike some of the гemarks look
like left by гain Ԁеad folks? :-P And, if you are
writing oon othеr onlіne sitеs, I'd like to keep up with
eveгything new you have to post. Could you list of every oone
of all yoսr public sites like your Facebook page,
twitter feed, oor linkedin profilе?

my web blog property Investment company

 

Post a Comment

<< Home