୍⯡♫ᅋἲே 㟁Ꮚ᝟ሗ㏻ಙᏛ఍                 ‫ٻ‬ಙᏛᢏሗ‫ٻ‬‫ٻۏۍۊۋۀڭٻۇڼھۄۉۃھۀگٻڠڞڤڠڤٻ                 ٻڇڮڞڤکڪڭگڞڠڧڠٻڡڪٻڠگڰگڤگڮکڤٻڠڣگ‬ࣾஂ๏ਓ ిࢠ৘ใ௨৴ֶձ
৴ֶٕใ‫ٻڮڭڠڠکڤڢکڠٻکڪڤگڜڞڤکڰڨڨڪڞٻڟکڜٻکڪڤگڜڨڭڪڡکڤ‬           ‫ٻڄڌڋڈڑڌڋڍڃٻڑړڈڐڌڋڍڡکڪڞڠڭڇڑڎڌڈڐڌڋڍڴڮګڞڇڏڋڌڈڐڌڋڍڟڧڱٻ‬THE INSTITUTE OF ELECTRONICS,TECHNICAL REPORT OF IEICE.
‫ٻ‬INFORMATION AND COMMUNICATION ENGINEERSϨΨγʔϚΠάϨʔγϣϯʹ͓͚ΔϝΠϯϑϨʔϜΞηϯϒϦͷ C ‫΁ޠݴ‬ͷม‫׵‬౻‫ ݪ‬େี†ੴӜࡊ‫†ࠤذ‬

ቒ†

ञҪ

੨໦

ྖ††

খՏ‫††ོ࢙ݪ‬† ؔ੢ֶӃେֶ ཧ޻ֶ෦ ˟ 669–1337 ฌ‫ֶࢢాࡾݝݿ‬Ԃ 2-1†† ‫ࣜג‬ձࣾγεςϜζ ˟ 141–0031 ౦‫౎ژ‬඼઒۠੢‫ޒ‬൓ా 7-24-5͋Β·͠ຊߘͰ͸, ϨΨγʔϚΠάϨʔγϣϯʹ͓͍ͯ, ϝΠϯϑϨʔϜίϯϐϡʔλͷΞηϯϒϦϓϩάϥϜΛ C‫ࣗ΁ޠݴ‬ಈม‫͢׵‬Δख๏ΛఏҊ͢Δ. ϨΨγʔϚΠάϨʔγϣϯͰ͸, ϝΠϯϑϨʔϜ্Ͱಈ࡞͢Δ‫ۀ‬຿γεςϜΛ

Linux ౳ͷΦʔϓϯγεςϜʹҠߦ͢Δ͕, ΞηϯϒϦϓϩάϥϜͷม‫ॲ׵‬ཧ͸ਓखͰߦΘΕ͓ͯΓ, ๲େͳ࣌ؒͱ޻
਺Λཁ͢Δ. ຊߘͰఏҊ͢Δख๏͸, COBOL ౳ͷαϒϧʔνϯͱͯ͠‫ͼݺ‬ग़͞ΕΔ IBM ϝΠϯϑϨʔϜͷΞηϯϒ
ϦΛର৅ʹ, ͜ΕΛਖ਼͘͠ಈ࡞͠, ͔ͭՄಡੑͷߴ͍ C ϓϩάϥϜʹม‫͢׵‬Δ. ຊख๏Ͱ͸, ΞηϯϒϦΛ SSA ‫ࣜܗ‬ͷதؒද‫ʹݱ‬ม‫͠׵‬, ͦͷதؒද‫Ͱ্ݱ‬σʔλϑϩʔղੳ, ੍‫ߏޚ‬଄ͷ࠶ߏங, ύλʔϯϚονϯάʹΑΔม‫׵‬Λߦ͏͜ͱʹΑΓ, Մಡੑͷߴ͍ C ϓϩάϥϜΛੜ੒͢Δ. ͞Βʹ, ຊख๏Ͱ͸, ΞʔΩςΫνϟґଘίʔυ΍ࣗ‫͑׵͖ॻݾ‬ίʔυͷม‫׬͕׵‬શʹߦ͑ͳ͔ͬͨ৔߹ͷमਖ਼࡞‫ۀ‬Λ༰қԽ͢ΔͨΊ, ‫ݩ‬ΞηϯϒϦͱม‫݁׵‬Ռͷ C ϓϩάϥϜͷରԠΛυΩϡϝϯτͱͯ͠ੜ੒͢Δ. ఏҊख๏ʹ‫ͮ͘ج‬πʔϧΛ Perl Ͱ࣮૷͠, ෳ਺ͷϝΠϯϑϨʔϜΞηϯϒϦΛਖ਼͘͠ಈ࡞͢Δ C ϓϩάϥϜʹม‫͖Ͱ׵‬Δ͜ͱΛ֬ೝͨ͠.
ΩʔϫʔυϨΨγʔϚΠάϨʔγϣϯ, ϝΠϯϑϨʔϜΞηϯϒϦ

Mainframe Assembly to C translation in Legacy Migration
Daisuke FUJIWARA† , Nagisa ISHIURA† , Ryo SAKAI† , Ryo AOKI†† , and Takashi OGAWARA††† Kwansei Gakuin University, 2–1 Gakuen, Sanda, Hyogo, 669–1337, Japan†† SYSTEM’S Co., Ltd. 7–24–5 Nishigotanda, Shinagawa-ku, Tokyo, 141–0031 Japan
Abstract This article presents a method of translating mainframe assembly programs to C programs. In “legacy
migration,” where enterprise systems running on mainframe computers are ported to open systems based on Linux,
etc., porting of assembly programs needs manual translation and takes enourmous amount of man-hours. In our
method, IBM mainframe assembly programs, which are called as subroutines from high-level languages such as
COBOL, are automatically translated into C programs which produce the same results and yet have good readability. Assembly programs are converted into intermediate representation with the SSA form on which dataﬂow
analysis, recovering of control structures, and pattern match based transformations are applied to produce highly
readable codes. Along with translation, correspondence between source assembly codes and resulting C codes arealso generated as documents, which plays an important role in manually correcting incomplete C codes from architecture dependent codes or self morphing codes. A prototype system based on our method successfully translated
some assembly codes into C program with function, if, and do-while structures.
Key words Legacy Migration, Mainframe Assembly

1. ͸ ͡ Ί ʹϝΠϯϑϨʔϜίϯϐϡʔλ͸, ߴ͍৴པੑ΍଱ো֐ੑΛ༗͓ͯ͠Γ, ଟ͘ͷ‫ۀا‬ͷ‫װج‬γεςϜʹ࠾༻͞Ε͍ͯΔ. ͔͠͠, ۙ೥, Linux ΍ Windows ౳ͷ௿Ձ֨ͳΦʔϓϯγεςϜ
ͷߴੑೳԽʹ൐͍, ϝΠϯϑϨʔϜ্ͰՔಇ͢ΔγεςϜ (ϨΨγʔγεςϜ) Λ͜ΕΒͷΦʔϓϯγεςϜʹҠߦ͢Δಈ͖
͕ग़͍ͯΔ. ϨΨγʔγεςϜʹ͸௕೥౉ͬͯ‫ۀ‬຿ͷϊ΢ϋ΢
͕஝ੵ͞Ε͍ͯΔ͜ͱ͕ଟ͍ͨΊ, ৽ͨʹγεςϜΛߏங͠௚͢ΑΓ΋, ‫ط‬ଘͷϨΨγʔγεςϜΛΦʔϓϯγεςϜʹҠ২͢ΔϝϦοτͷํ͕େ͖͍৔߹͕͋Δ. ͜ͷΑ͏ͳҠ২͸ϨΨγʔϚΠϯάϨʔγϣϯ (legacy migration) ͱ‫ݺ‬͹Ε, େ‫ن‬໛- 203 -

—1—
Copyright ©2016 by IEICEThis article is a technical report without peer review, and its polished and/or extended version may be published elsewhere.

ͳγεςϜΛ೗Կʹޮ཰Α͘Ҡ২͢Δ͔͕ॏཁͳٕज़՝୊ͱͳ͍ͬͯΔ.
ϨΨγʔϚΠάϨʔγϣϯͰ͸, COBOL, PL/1, ΞηϯϒϦ
౳Ͱ‫ه‬ड़͞ΕͨϝΠϯϑϨʔϜ༻ͷϓϩάϥϜΛ, ৽͍͠γεςϜͰಈ࡞͢ΔΑ͏ʹม‫͢׵‬Δ͜ͱ͕Ұͭͷதٕ֩ज़ͱͳΔ.
ߴ‫ʹޠݴڃ‬ΑΔϓϩάϥϜͰ͋Ε͹, ࠶ίϯύΠϧͰಈ࡞͢Δ
΋ͷ΋͋Ε͹, ࣗಈม‫׵‬πʔϧ΋छʑ։ൃ͞Ε͍ͯΔ [1]. ·ͨ,ίʔυ͕ཧղ͠΍͍ͨ͢Ί, Ҡ২ʹࡍͯ͠ඞཁͱͳΔमਖ਼΋ൺֱత༰қʹߦ͑Δ. ͜Εʹର͠, ΞηϯϒϦ͸ͦͷ··ಈ࡞͞
ͤΔ͜ͱ͕Ͱ͖ͳ͍ͨΊ, ಈ࡞Λཧղ্ͨ͠ͰਓखͰߴ‫ޠݴڃ‬ʹม‫͢׵‬Δඞཁ͕͋Δ͕, ίʔυͷཧղʹ͸ΞʔΩςΫνϟͷ
ৄࡉʹؔ͢Δ஌ࣝͱख़࿅͕ඞཁʹͳΔ. Ҡߦର৅ͱͳΔϓϩάϥϜ͸ 1 γεςϜʹ͖ͭ਺ඦ͔Β਺ઍຊʹ‫ͨͿٴ‬Ί, ͜ͷม‫׵‬ʹ͸๲େͳ޻਺͕ඞཁͱͳΔ.
͜ͷ՝୊Λղܾ͢ΔͨΊ, ΞηϯϒϦίʔυ͔Βߴ‫΁ޠݴڃ‬ͷม‫׵‬ͷࣗಈԽ͕ࢼΈΒΕ͍ͯΔ. ΞηϯϒϦίʔυͷϚΠά
Ϩʔγϣϯʹ͓͍ͯ͸, ม‫ͨ͠׵‬ϓϩάϥϜ͕ਖ਼͘͠ಈ࡞͢Δ
ͱ͍͏͜ͱʹՃ͑, ม‫ޙ׵‬ͷϓϩάϥϜͷσόοά΍อकͷͨΊʹՄಡੑ͕ߴ͍͜ͱ͕ඞཁͱͳΔ.
จ‫[ ݙ‬5] [6] [7] [8] Ͱ͸, IBM ϝΠϯϑϨʔϜͷΞηϯϒϦΛC ϓϩάϥϜʹม‫͢׵‬Δख๏ΛఏҊ͍ͯ͠Δ. ΞηϯϒϦΛதؒද‫ʹݱ‬ม‫͠׵‬, தؒද‫Ͱ্ݱ‬৑௕ͳίʔυͷ࡟আ΍੍‫ߏޚ‬଄ͷநग़, ؔ਺ͷΠϯλʔϑΣʔεͷ࡞੒, ϩʔΧϧม਺ͷ‫ܕ‬৘ใͷղੳ౳Λߦ͍, Մಡੑͷߴ͍ C ϓϩάϥϜΛੜ੒͍ͯ͠Δ.
͔͠͠, ม‫׵‬ର৅ͷΞηϯϒϦʹ͸ΞʔΩςΫνϟʹ‫͘ڧ‬ґଘͨ͠ίʔυ΍ࣗ‫ݾ‬Λॻ͖‫͑׵‬ΔΑ͏ͳίʔυ͕‫·ؚ‬Ε͍ͯΔ
͜ͱ͕͋Γ, ੜ੒͞Εͨ C ϓϩάϥϜ͸ඞͣ͠΋ਖ਼͘͠ಈ࡞͢
Δͱ͸‫ݶ‬Βͳ͍. ͜ͷΑ͏ͳ৔߹ʹ͸, ม‫͞׵‬ΕͨίʔυΛਓखͰमਖ਼͠ͳ͚Ε͹ͳΒͳ͍͕, ͜ͷࡍʹ, ΞηϯϒϦͷιʔείʔυͱੜ੒͞Εͨ C ϓϩάϥϜͷରԠ͕औΕΔ͜ͱ͕ඇৗ
ʹॏཁʹͳΔ.
ͦ͜ͰຊߘͰ͸, IBM ΞηϯϒϦͷ C ‫΁ޠݴ‬ͷࣗಈม‫׵‬Λߦ͏ͱͱ΋ʹ, ม‫׵‬աఔͷυΩϡϝϯτԽΛߦ͏ख๏ΛఏҊ͢Δ.
ຊख๏Ͱ͸, จ‫[ ݙ‬5] [6] [7] [8] ͱಉ༷ʹ, ΞηϯϒϦΛதؒද‫ݱ‬ʹม‫͠׵‬, ͦͷද‫਺ؔͰ্ݱ‬, if จ, ϧʔϓจͷ࠶ߏ੒Λߦͬͯ,ߏ଄Խ͞Εͨ C ϓϩάϥϜΛग़ྗ͢Δ. ͜ͷͱ͖, ม‫׵‬աఔ͕֬ೝͰ͖ΔΑ͏, ม‫ݩ׵‬ϓϩάϥϜͱੜ੒͞Εͨ C ϓϩάϥϜ
ͷରԠؔ܎Λࣔ͢දΛಉ࣌ʹੜ੒͢Δ.
ఏҊख๏ʹ‫ͮ͘ج‬πʔϧΛ Perl5.18.4 Ͱ࣮૷͠, ͍͔ͭ͘ͷΞηϯϒϦϓϩάϥϜʹ͍ͭͯม‫׵‬Λߦͬͨ݁Ռ, ਖ਼͘͠ಈ࡞
͢Δ C ϓϩάϥϜΛੜ੒͢Δ͜ͱ͕Ͱ͖ͨ.
ҎԼ, ຊߘͰ͸ 2 ষͰΞηϯϒϦͷϚΠάϨʔγϣϯʹ͍ͭͯཁ఺Λ੔ཧ͠, 3 ষͰΞηϯϒϦͷ C ‫΁ޠݴ‬ͷม‫͍ͯͭʹ׵‬,
4 ষͰυΩϡϝϯτԽͷख๏ʹ͍ͭͯड़΂Δ. 5 ষͰ࣮૷ʹ͍ͭͯड़΂ͨ‫ޙ‬, 6 ষͰ·ͱΊͱࠓ‫ޙ‬ͷ՝୊Λड़΂Δ.

2. ΞηϯϒϦͷϚΠάϨʔγϣϯ
2. 1 ม‫׵‬ͷର৅ຊߘͰ͸, ਓखͰॻ͔Εͨ IBM 370ʙ390 ϝΠϯϑϨʔϜͷΞηϯϒϦϓϩάϥϜΛ C ‫ޠݴ‬ϓϩάϥϜʹม‫͢׵‬Δ໰୊Λѻ͏. ର৅ΞηϯϒϦ͸, ਤ 1 ʹࣔ͢Α͏ʹ, COBOL ౳Ͱॻ͔ΕͨଞͷϓϩάϥϜ͔Βαϒϧʔνϯͱͯ͠‫ͼݺ‬ग़͞ΕΔ΋ͷΛ૝ఆ͢Δ. ΞηϯϒϦ͕‫ͼݺ‬ग़͢ϥΠϒϥϦ΍ϚΫϩʹରͯ͠͸, ৽͍͠γεςϜ্Ͱಈ࡞͢ΔϥΠϒϥϦ͕ผ్४උ͞
Ε͍ͯΔ΋ͷͱ͢Δ.
͜ͷΑ͏ͳม‫ͣ·͍͓ͯʹ׵‬ॏཁʹͳΔͷ͸, ม‫݁׵‬Ռͷϓ

ਤ 1 ม‫׵‬ͷର৅ϩάϥϜ͕ਖ਼͘͠ಈ࡞͢Δ͜ͱͰ͋Γ, όΠφϦτϥϯεϨʔγϣϯ [2] ͱಉ༷ͷٕज़͕ඞཁʹͳΔ. ·ͨ, ม‫݁׵‬ՌͷϓϩάϥϜΛอक͢Δඞཁੑ͔Β, ϓϩάϥϜͷՄಡੑ͕ߴ͍͜ͱ΋ॏཁʹͳΔ. ͜Εʹ͸‫ٯ‬ίϯύΠϧ [3] [4] ͱಉ༷ͷٕज़͕ඞཁ
ʹͳΔ.
ϝΠϯϑϨʔϜΞηϯϒϦΛߴ‫ʹޠݴڃ‬ม‫͢׵‬Δπʔϧ͸͍͔ͭ͘։ൃ͞Ε͍ͯΔ [5] [6] [7] [8]. ͜ͷ͏ͪ, จ‫[ ݙ‬5] Ͱ͸HLL, จ‫[ ݙ‬6] [7] [8] Ͱ͸ WSL ͱ‫ݺ‬͹ΕΔதؒ‫ͦͱޠݴ‬Εʹର͢Δม‫ʹ׵‬ΑΓ, IBM ΞηϯϒϦ͔ΒՄಡੑͷߴ͍ C ϓϩάϥϜΛੜ੒͍ͯ͠Δ.
͔͠͠, ΞηϯϒϦϓϩάϥϜʹ͸, ΤϯσΟΞϯ΍࢖༻͢Δ
ΞυϨεۭؒͷϚοϓ, ΞυϨεࢦఆ࣌ͷϏοτύλʔϯ (αϒϧʔνϯίʔϧʹ͓͍ͯ࠷‫ޙ‬ͷύϥϝλͷΞυϨεͷ࠷্ҐϏοτΛ 1 ʹηοτ͢Δ) ౳, ΞʔΩςΫνϟ (৔߹ʹΑͬͯ͸ಛఆͷϞσϧͷϚΠΫϩΞʔΩςΫνϟ) ʹґଘͨ͠ίʔσΟϯά͕ߦΘΕΔ͜ͱ͕͋Δ. ͞Βʹ, ໋ྩͷҰ෦·ͨ͸શͯΛॻ͖‫͑׵‬Δ “self morphing code” ΍, खॻ͖Ξηϯϒϥಛ༗ͷίʔσΟϯάٕ๏͕༻͍ΒΕΔ͜ͱ͕͋ΔͨΊ, ม‫׵‬ͷ‫׬‬શͳࣗಈԽ͸ඞͣ͠΋ՄೳͰ͸ͳ͍. ม‫ࣦ͕׵‬ഊͨ͠৔߹ʹ͸, ͦͷ‫ݪ‬ҼΛಥ͖ࢭΊͯਓखͰमਖ਼Λߦ͏ඞཁ͕͋Δ͕, ͜ͷࡍʹ͸, ‫ݩ‬ͷΞηϯϒϦͱม‫݁׵‬ՌͷରԠؔ܎Λ೺ѲͰ͖Δ͜ͱ͕ඇৗʹॏཁͱͳΔ.
2. 2 IBM ΞηϯϒϦ
IBM ϝΠϯϑϨʔϜ͸ 32bit ΞʔΩςΫνϟͰ͋Γ, 0ʙ15ͱ൪߸෇͚ΒΕͨ 16 ຊͷϨδελΛ࣋ͭ. IBM ΞηϯϒϦ͕ѻ͑Δσʔλ‫ʹܕ‬͸ 32bit (full word), 16bit (half word), 8bit
(character), ύοΫ‫ ࣜܗ‬10 ਐ਺, κʔϯ‫ ࣜܗ‬10 ਐ਺౳͕͋Δ.
ΞυϨογϯάʹ͸ 24bit Ϟʔυͱ 31bit Ϟʔυ͕͋Δ. ໋ྩ͸ 0ʙ3 ΦϖϥϯυΛ࣋ͪ, 2 ਐ਺, 10 ਐ਺, จࣈྻ౳ʹର͢Δ
໋ྩΛ‫ؚ‬Ί, ߹‫ ܭ‬631 ‫ݸ‬ͷ໋ྩ͕͋Δ.
IBM ΞηϯϒϦͷྫΛਤ 2 ʹࣔ͢. ͜ͷίʔυ͸, ‫ͼݺ‬ग़͠ଆ͔Β 2 ͭͷύϥϝλΛड͚औΓ, 1 ͭ໨ͷύϥϝλͰड͚औͬ
ͨ YYYYMMDD ‫ࣜܗ‬ͷ೔෇σʔλͷ݄ͷ຤೔Λ YYYYMMDD ‫Ͱࣜܗ‬
2 ͭ໨ͷύϥϝλʹอଘ͢Δ΋ͷͰ͋Δ.

3. ϝΠϯϑϨʔϜΞηϯϒϦͷ C ‫΁ޠݴ‬ͷม‫׵‬
3. 1 ֓
ཁຊߘͷม‫ॲ׵‬ཧͷྲྀΕΛਤ 3 ʹࣔ͢. ΞηϯϒϦϓϩάϥϜ
Λߏจղੳ໋֤ͯ͠ྩΛΞτϛοΫͳԋࢉʹ෼ղ͠, SSA ‫ࣜܗ‬(੩త୯Ұ୅ೖ‫ )ࣜܗ‬ͷதؒද‫( ݱ‬IR) ʹม‫͢׵‬Δ. ͜Εʹରͯ͠σʔλϑϩʔղੳ, ੍‫ߏޚ‬଄ͷநग़, ύλʔϯϚονϯάʹΑ
Δม‫׵‬౳ͷՄಡੑ޲্ॲཧΛߦ͍, தؒද‫͔ݱ‬Β C ‫ޠݴ‬Λੜ੒͢Δ.
3. 2 த ؒ ද ‫ݱ‬ຊߘͰѻ͏தؒද‫ݱ‬ͷߏ଄Λ ਤ 4 ʹࣔ͢. ม‫׵‬ର৅ͷΞηϯϒϦશମΛද͢ Assembly ͸ 1 ͭͷ SymbolTable ͱ 1 ͭҎ্ͷ Section Λอ࣋͢Δ. SymbolTable ͸ΞηϯϒϦͷ࣋ͭશͯͷม਺, ؔ਺, ϥϕϧͷ৘ใΛอ࣋͢Δ. Section ͸ΞηϯϒϦͷ

- 204 -

—2—

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:

EMONTH

ER_FMT
FC_EOM
EOM

EOM1

RET

MLAST

SAVE
WORK

CSECT
USING
STM
LA
LA
ST
ST
LR
LM
CLC
BNE
B
EQU
ABEND
BAL
EQU
MVC
LA
LR
EQU
CLI
BL
CLI
BH
LA
BCT
CLC
BL
CLC
BH
PACK
CVB
BCTR
MH
LA
AR
LH
SH
CVD
UNPK
OI
MVC
B
EQU
L
LM
SLR
BR
DC
DC
DC
DC
DC
DC
DC
DC
DC
DC
DC
DC
DC
LTORG
DS
DS
DROP
LTORG
SPACE
END

EMONTH ,12
14 ,12 ,12(13)12 ,0( ,15)
15 , SAVE
13 ,4( ,15)
15 ,8( ,13)
13 ,15
3 ,4 ,0(1)0(6 ,4) ,=C ’00000000 ’
ER_FMT
FC_EOM*
0999 , DUMP
14 , EOM*
0(8 ,4) ,= CL9 ’ ’
0 ,6
1 ,3
*
0(1) ,C ’0 ’
RET
0(1) ,C ’9 ’
RET
1 ,1( ,1)
0 , EOM1
4(2 ,3) ,=C ’01 ’
RET
4(2 ,3) ,=C ’12 ’
RETWORK ,4(2 ,3)
2 , WORK2 ,0
2 ,=H ’4 ’
5 , MLAST
2 ,5
0 ,4( ,2)0 ,0( ,2)0 , WORK
6(2 ,4) , WORK
7(4) ,X ’ F0 ’
0(6 ,4) ,0(3)RET*
13 ,4( ,13)
14 ,12 ,12(13)15 ,1514
H ’000 ’ , H ’000 ’
H ’031 ’ , H ’031 ’
H ’059 ’ , H ’060 ’
H ’090 ’ , H ’091 ’
H ’120 ’ , H ’121 ’
H ’151 ’ , H ’152 ’
H ’181 ’ , H ’182 ’
H ’212 ’ , H ’213 ’
H ’243 ’ , H ’244 ’
H ’273 ’ , H ’274 ’
H ’304 ’ , H ’305 ’
H ’334 ’ , H ’335 ’
H ’365 ’ , H ’366 ’
18 F
D
12

00000000
00000100
00000200
00000300
00000400
00000500
00000600
00000700
00000800
00001100
00001200
00001300
00001400
00001500
00001600
00001700
00001800
00001900
00002000
00002100
00002200
00002300
00002400
00002500
00002600
00002700
00003000
00003100
00003200
00003300
00003400
00003500
00003600
00003700
00003800
00003900
00004000
00004100
00004200
00004300
00004400
00004500
00004600
00004700
00004800
00004900
00005000
00005100
00005200
00005300
00005400
00005500
00005600
00005700
00005800
00005900
00006000
00006100
00006200
00006300
00006400
00006500
00006600
00006700
00006800
00006900
00007000
00007100

ਤ 4 தؒද‫ݱ‬ͷσʔλߏ଄
ද1໋ྩ͔Βதؒද‫΁ݱ‬ͷม‫ྫ׵‬ΞηϯϒϦதؒද‫( ݱ‬IR)
addr = addu32(r13, 4)
r11 = load32(addr)
AP DAT1,DAT2+5(3) cc=addpack(DAT1, 8, DAT2, 8)
CLC 4(2,4),=C’01’ addr=addu32(r4, 4)
cc=compstr(addr, C’01’, 2)

L 11,4(,13)

USING *,12STM
14,12,12(13)˰using(256,12)
addr0=addu32(r13,12)
store32(r14,addr0)
addr1=addu32(r13,16)
˰store32(r15,addr1)
addr2=addu32(r13,20)
store32(r0,addr2)
addr3=addu32(r13,24)
ɾɾɾ

using(256,12)ɾɾɾ

ਤ 5 ୀආίʔυͷ࡟আ

ਤ 2 IBM ϝΠϯϑϨʔϜΞηϯϒϦ

ਤ 3 ม‫ॲ׵‬ཧͷྲྀΕηΫγϣϯΛද͠, Function ͷϦετΛ࣋ͭ. Function ͸ؔ਺(αϒϧʔνϯ) Λද͠, BasicBlock, If, Loop ͷϦετΛ࣋ͭ.
If ͸ if จΛද͠, ৚݅, then ෦, else ෦Λ࣋ͭ. then ෦ͱ else ෦͸ BasicBlock, If, Loop ͷϦετΛ࣋ͭ. Loop ͸ do-while จΛද͠, ৚݅ͱ body ෦Λ࣋ͪ, body ෦͸ BasicBlock, If, LoopͷϦετΛ࣋ͭ. BasicBlock ͸‫ج‬ຊϒϩοΫΛද͠, OperationͷϦετͱ࣍ͷ BasicBlock ΁ͷϦϯΫΛ࣋ͭ. Operation ͸ԋࢉ (ࢉज़ɾ࿦ཧԋࢉ, ϝϞϦͷϩʔυɾετΞ, จࣈྻ΍ 10
ਐ਺σʔλʹର͢Δԋࢉ౳) Λද͢΋ͷͰ͋Γ, ෳ਺ͷΦϖϥϯυʹରͯ͠ԋࢉΛద༻ͨ݁͠ՌΛม਺ʹ֨ೲ͢Δ.
໋ྩͷ Operation ΁ͷม‫ྫ׵‬Λද 1 ʹࣔ͢. ϩʔυ໋ྩ L͸, ΞυϨεΛ‫͢ࢉܭ‬Δԋࢉ (addu32) ͱϝϞϦΛಡΉԋࢉ(load32) ʹม‫͢׵‬Δ. AP ໋ྩ౳ͷύοΫ‫ ࣜܗ‬10 ਐ਺΍ CLC
໋ྩ౳ͷจࣈྻʹର͢Δॲཧ͸, ΞτϛοΫͳԋࢉͱͯ͠ѻ͏.
໋ྩม‫׵‬ͷ݁ՌಘΒΕΔ Operation ͷϦετ͸ SSA ‫ʹࣜܗ‬ม‫͢׵‬Δ. SSA ‫ࣜܗ‬Λ༻͍Δ͜ͱʹΑΓ, ҙຯ͸ಉ͕ͩ͡ද‫ݱ‬͕ҟͳΔίʔυͷதؒද‫͕ݱ‬ඪ४Խ͞ΕΔ. ·ͨ, SSA ม‫׵‬͸
3. 3 અ, 3. 6 અͰड़΂Δෆཁίʔυͷ࡟আ΍ύλʔϯϚονϯά

ॲཧΛޮ཰తʹߦ͏্Ͱ΋༗༻Ͱ͋Δ. ͜ͷ‫ޙ‬, ࠷‫ʹޙ‬σʔλϑϩʔղੳΛߦͬͯ, ม਺ͷఆٛ/ࢀরؔ܎Λσʔλߏ଄ͱͯ͠
อ࣋͢Δ.
3. 3 Ϩδελୀආ/෮‫ؼ‬ίʔυͱෆཁίʔυͷ࡟আσʔλϑϩʔղੳͷ݁Ռʹ‫͖ͮج‬, ߴ‫Ͱޠݴڃ‬͸ෆཁʹͳΔϨδελͷୀආ/෮‫ؼ‬ίʔυͷ࡟আΛߦ͏. ࣍ͷ৚݅ʹ֘౰͢ΔԋࢉΛୀආίʔυ, ෮‫ؼ‬ίʔυͱ൑ఆ͠, ࡟আ͢Δ.
• ୀආίʔυʢ 1 ʣ ԋࢉ͕ store32 (32bit σʔλͷϝϞϦॻ͖ࠐΈ)ʢ 2 ʣ ୈ 1 Φϖϥϯυ͕Ҏ߱ͷଞͷԋࢉͰ࢖༻͞Ε͍ͯͳ͍ʢ 3 ʣ ୈ 2 Φϖϥϯυ͕Ϩδελ 13 ʹ 0ʙ68 ΦϑηοτΛ
Ճࢉͨ͠΋ͷͰ͋Δ.
• ෮‫ؼ‬ίʔυ
ʢ 1 ʣ ԋࢉ͕ load32 (32bit σʔλͷϝϞϦಡΈࠐΈ)
ʢ 2 ʣ ԋࢉͷ݁ՌΛ֨ೲ͢Δม਺͕Ϩδελʢ 3 ʣ ୈ 1 Φϖϥϯυ͕Ϩδελ 13 ʹ 0ʙ68 ΦϑηοτΛ
Ճࢉͨ͠΋ͷͰ͋Δ.
ୀආίʔυͷ࡟আྫΛਤ 5 ʹࣔ͢. STM (store multiple) ໋ྩ͸, શϨδελΛୀආ͢ΔͨΊͷΞυϨε‫ͱࢉܭ‬ετΞΛߦ͏ͨΊͷதؒද‫ʹݱ‬Ұ୴ม‫͢׵‬Δ͕, ͜ΕΒ͸ୀආίʔυͷ൑ఆ৚݅ʹ֘౰͢ΔͨΊ, ࡟আ͢Δ.
·ͨ, ΞηϯϒϦதʹ͸, อकͷաఔͰ࢖༻͞Εͳ͘ͳͬͨ
ίʔυ͕‫·ؚ‬Ε͍ͯΔ͜ͱ͕ଟ͍. ຊख๏Ͱ͸ೖ‫͔఺ޱ‬ΒͷՄୡੑղੳʹΑΓ, ͜ΕΒͷίʔυʹର͢Δதؒද‫ݱ‬Λ࡟আ͢Δ.
3. 4 ੍‫ߏޚ‬଄ͷநग़தؒද‫ʹݱ‬ର͠, ؔ਺, if จ, do-while จͷ੍‫ߏޚ‬଄Λநग़͠,ߏ଄ԽΛߦ͏.

- 205 -

—3—

reachable to b
1

body
t

4
11

loop

3

10
5

6

t

9

3
4

1

1

reachable from t

0

f

9

reachable ffrom t

10

t

5

4

6

1

11

2

0

3

11

6

12

7

13

4
14

2

reachablefrom e

3

e 11

6

12

7

13

14

j

b

12

b

8

12

8

9

5

8

8

ਤ 6 ϧʔϓͷຊମͷநग़

9

5

10

10

ਤ 7 ෼‫఺ྲྀ߹ͱ఺ذ‬ͷબ୒

3. 4. 1 ؔ਺ͷநग़ؔ਺ͷநग़͸, ؔ਺ͷೖ‫͔ޱ‬ΒϦλʔϯ·Ͱͷ౸ୡՄೳͳશ
ͯͷ‫ج‬ຊϒϩοΫΛྻ‫͢ڍ‬Δ͜ͱʹΑͬͯߦ͏. ·ͣ, ϓϩάϥϜશମͷೖ‫ޱ‬, ͓Αͼ BAL, BALR, BAS ౳ͷؔ਺‫ͼݺ‬ग़͠ͷ໋ྩͷλʔήοτΛؔ਺ೖ‫ޱ‬ͷू߹ͱͯ͠ྻ‫͢ڍ‬Δ. ࣍ʹ, ֤ؔ਺ͷೖ‫͔ޱ‬Β౸ୡՄೳͳ‫ج‬ຊϒϩοΫΛͦͷؔ਺໊ͰϚʔΫ͢Δ. ϚʔΫ͞Εͨ‫ج‬ຊϒϩοΫΛͦͷؔ਺ͷ࣋ͭ‫ج‬ຊϒϩοΫ
ू߹ͱ͢Δ. ͨͩ͠, ‫ج‬ຊϒϩοΫ͕ෳ਺ͷؔ਺໊ͰϚʔΫ͞Ε͍ͯΔ৔߹͸, ͦͷ‫ج‬ຊϒϩοΫͷΫϩʔϯΛ࡞੒͢Δ.
3. 4. 2 do-while จͷநग़
do-while จͷೝࣝ͸࣍ͷखॱͰߦ͏.
ʢ 1 ʣ ೝࣝͷ‫ॳ࠷( ఺ى‬͸ؔ਺ͷೖ‫͔ )ޱ‬Β‫ج‬ຊϒϩοΫΛͨͲΓ, ϧʔϓΛྻ‫͢ڍ‬Δ.
ʢ 2 ʣ ॲཧର৅ͱ͢ΔϧʔϓΛ 1 ܾͭఆ͢Δ. ϧʔϓ͕ෳ਺͋Ε͹, ϧʔϓͷϘτϜ b ͕‫͔఺ى‬Β࠷΋ԕ͍΋ͷΛબͼ, ͞ΒʹϘτϜ͕ b Ͱ͋Δϧʔϓ͕ෳ਺͋Δ৔߹͸, τοϓ t ͕‫ى‬఺ʹ࠷΋͍ۙ΋ͷΛબͿ. ͜Ε͸, ֎ଆͷϧʔϓ͔Βઌʹೝࣝ͠, ϧʔϓ΁ͷඈͼࠐΈ͕ൃੜ͢ΔͷΛආ͚ΔͨΊͰ͋Δ.
ʢ 3 ʣ ϧʔϓຊମΛߏ੒͢Δ‫ج‬ຊϒϩοΫͷू߹ B Λ‫ٻ‬Ί
Δ. B ͸τοϓ t ͔Β౸ୡՄೳ͔ͭϘτϜ b ΁౸ୡՄೳͳ‫ج‬ຊϒϩοΫΛྻ‫ͨ͠ڍ‬΋ͷͰ͋Δ (ਤ 6 ࢀর).
ʢ 4 ʣ ϘτϜ b ͷ෼‫ذ‬৚͔݅Βϧʔϓͷ‫ܧ‬ଓ৚݅Λநग़͠,ϧʔϓͷσʔλߏ଄Λ‫׬‬੒ͤ͞Δ.
ʢ 5 ʣ ϧʔϓͷຊମ‫ͨͬ࢒ͼٴ‬෦෼ʹରͯ͠ಉ༷ͷॲཧΛߦ͏.
3. 4. 3 if จͷநग़if จͷೝࣝ͸࣍ͷखॱͰߦ͏.
ʢ 1 ʣ ॲཧର৅ͱ͢Δ if ͷ෼‫ ఺ذ‬f ͱ߹ྲྀ఺ j Λ‫ٻ‬ΊΔ. ೝࣝͷ‫ॳ࠷( ఺ى‬͸ؔ਺ͷೖ‫͔ )ޱ‬Β‫ج‬ຊϒϩοΫΛͨͲΓ, ‫఺ى‬ʹ࠷΋͍ۙ‫ج‬ຊϒϩοΫΛ 1 ͭબΜͰ f ͱ͢Δ. f ͷ 2 ͭͷ෼‫ذ‬ઌ t, e ͷ྆ํ͔Β౸ୡՄೳͳ‫ج‬ຊϒϩοΫͷू߹ͷதͰ, fʹ࠷΋͍ۙ΋ͷΛ߹ྲྀ఺ j ͱ͢Δ (ਤ 7 ࢀর). ͜Ε͸, if จͷthen ෦, else ෦΁ͷඈͼࠐΈΛͳͨ͘͢ΊͰ͋Δ. ͨͩ͠, ू߹͕ۭू߹ͷ৔߹͸ j ͸ଘࡏ͠ͳ͍΋ͷͱ͢Δ.
ʢ 2 ʣ if ͷ then ଆʹ‫·ؚ‬ΕΔ‫ج‬ຊϒϩοΫͷू߹ T , else ଆʹ‫·ؚ‬ΕΔ‫ج‬ຊϒϩοΫͷू߹ E Λ‫ٻ‬ΊΔ. ·ͣ t ͔Β౸ୡՄೳͳ‫ج‬ຊϒϩοΫͷू߹ T  Λ‫ٻ‬ΊΔ. ࣍ʹ, T  Ҏ֎ͷ‫ج‬ຊϒϩοΫ͔Β௚઀౸ୡՄೳͳ‫ج‬ຊϒϩοΫ x ͱ, x ͔Β౸ୡՄೳͳ‫ج‬ຊϒϩοΫΛ T  ͔Βશͯ࡟আͨ͠΋ͷΛ T ͱ͢Δ. E ΋ಉ༷ʹͯ͠‫ٻ‬ΊΔ (ਤ 8 ࢀর).
ʢ 3 ʣ if ͷ৚݅෦Λநग़͠, σʔλߏ଄Λ‫׬‬੒ͤ͞Δ.
ʢ 4 ʣ T , E, ͓Αͼ࢒ͬͨ෦෼ʹରͯ͠ಉ༷ͷॲཧΛߦ͏.
3. 5 C ‫΁ޠݴ‬ͷม‫ ͱ׵‬DSECT ͷѻ͍தؒද‫ݱ‬͸, ‫ج‬ຊతʹ΄΅ͦͷ·· C ϓϩάϥϜʹม‫͖Ͱ׵‬Δ. Ϩδελ‫ͼٴ‬ΞηϯϒϦதͷม਺͸ C ‫ޠݴ‬ͷม਺ͱ͠, ࢛

10reachable ffrom t
t
4

8
5

1

2

0

3

e 11

6

12

7

13

T
t
4

14

j
9

8
5

10

ਤ8

f

2

1

reachablefrom e

3

e 11

6

12

7

13

0

T
t
4

14

2

8
5

E

3

e 11

6

12

7

j
9
10

f

13

14

j
9
10

if จͷ then ෦ͱ else ෦ͷநग़

ද 2 தؒද‫͔ݱ‬Β C ΁ͷม‫ྫ׵‬தؒද‫( ݱ‬IR)C
r10 = add32(r10, r7)
r10 = r10 + r7
cc = addpack(DAT1, 8, DAT2, 8) cc = addpack(DAT1, 8, DAT2, 8)
cc = compstr(addr, C’01’, 2)
cc = compstr( (char*) addr, "01", 2 )ଇɾ࿦ཧԋࢉ΍ϝϞϦͷϩʔυɾετΞ౳ͷԋࢉ͸, ͦͷ··
C ͷରԠ͢Δԋࢉʹม‫͢׵‬Δ. ·ͨ, จࣈྻ΍ 10 ਐ਺ʹର͢Δ
ԋࢉ͸, ඪ४ϥΠϒϥϦ·ͨ͸ผ్࡞੒ͨ͠ϥΠϒϥϦͷ‫ͼݺ‬ग़͠ʹม‫͢׵‬Δ. ද 3. 5 ʹม‫׵‬ͷҰྫΛࣔ͢. தؒද‫ݱ‬தͷ 10
ਐԋࢉ (addpack) ΍จࣈྻԋࢉ (compstr) ͸, ରԠ͢ΔϥΠϒϥϦͷ‫ͼݺ‬ग़͠ʹม‫͢׵‬Δ.
ͨͩ͠, ԋࢉ୯ҐͰ C ͷจʹ͢Δͱதؒม਺͕ଟ͘‫ݱ‬ΕͯՄಡੑ͕௿Լ͢ΔͨΊ, Մೳͳ‫ݶ‬Γෳ਺ͷԋࢉΛ·ͱΊͯҰͭͷจʹ͢Δ. ͜ͷॲཧͷྫΛਤ 9 ʹࣔ͢. C1 ͷΑ͏ͳԋࢉ‫ྻܥ‬͸, πϦʔߏ଄Λࣜͱͯ͠ग़ྗ͢Δ. ͨͩ͠, C2 ͷΑ͏ʹಉ͡தؒ݁Ռ͕ෳ਺ճ࢖༻͞Ε͍ͯΔ৔߹ʹ͸, πϦʔΛ෼ׂͯ͠
ग़ྗ͢Δ.
IBM ΞηϯϒϦͷμϛʔηΫγϣϯ (DSECT) ͸, ‫ػ‬ց໋ྩ΋ྖҬ΋ੜ੒͠ͳ͍ηΫγϣϯͰ͋Γ, αϒϧʔνϯؒͰड͚౉
͢େ͖ͳσʔλྖҬ಺ͷσʔλ഑ஔΛ‫ه‬ड़͢ΔͨΊʹ࢖ΘΕΔ.
ຊߘͰ͸ DSECT ʹΑΔσʔλͷ഑ஔΛߏ଄ମͰද͠, USING ໋ྩͰఆٛ͞ΕΔϕʔεϨδελΛ͜ͷߏ଄ମ΁ͷϙΠϯλͱͯ͠༻͍ͯΞΫηε͢Δ C ίʔυΛੜ੒͢Δ. DSECT ͷม‫ྫ׵‬Λ
ਤ 10 ʹࣔ͢. ม਺ A ͱ B Λ࣋ͭ DAT1 ͱ͍͏μϛʔηΫγϣϯ͕એ‫͞ݴ‬Ε, CSECT ௚‫ݱʹޙ‬ΕΔ USING ʹΑͬͯ Ϩδελ 2
Λ DAT1 ʹର͢ΔϕʔεϨδελͱ͍ͯ͠Δ. DAT1 ͸ DAT1 tͱ͍͏ߏ଄ମ‫ʹܕ‬ม‫͠׵‬, αϒϧʔνϯ MAIN Λม‫਺ؔͨ͠׵‬main ಺Ͱ͸, r2 Λ DAT1 t ΁ͷϙΠϯλͱͯ͠༻͍Δ͜ͱʹΑΓͦͷϝϯόʹΞΫηεͰ͖ΔΑ͏ʹ͢Δ.
3. 6 ύλʔϯϚονϯάʹΑΔՄಡੑ޲্
ຊख๏Ͱ͸, ύλʔϯϚονϯάʹ‫ͮ͘ج‬தؒද‫ݱ‬ͷม‫ʹ׵‬ΑΓ, ͞ΒͳΔՄಡੑͷ޲্ΛਤΔ. ͜Ε͸ SSA ม‫͞׵‬Εͨதؒද‫ݱ‬தͷ෦෼໦Λॻ͖‫͑׵‬ΔϧʔϧΛ४උ͢Δ͜ͱʹΑΓ࣮‫͢ݱ‬Δ. ྫ͑͹, ਤ 11(a) ͷ ASM ͷΑ͏ͳจࣈྻൺֱʹΑΔ෼‫ذ‬͸, தؒද‫ ݱ‬IR Λ‫ ͯܦ‬C ͷΑ͏ʹ৚݅ cc Λ‫ؚ‬Ή C ϓ- 206 -

—4—

C1

C1’

r1 = mul32(r1, X)
r1 = add32(r1, Y) ˰
r1 = mul32(r1, Z)

r1 = ((r1 * X) + Y) * Z;

C2

C2’

r1 = mul32(r1, X)
r2 = load32(r1)r1 = add32(r1, Y) ˰
r1 = mul32(r1, Z)
r2 = add32(r2, T)

r2 = r1 * X;
r1 = (r2 + Y) * z;
r2 = r2 + T(a) ରԠؔ܎ͷߏஙΞηϯϒϦC ‫ޠݴ‬
උߟ1

STM 14,12,12(13)2L 11,4(,13)
uint32 t addr0 = r13+4;
r11=*(uint32 t*)addr0;3
AH 0,0(,2)
uint32 t addr1=r2;
ԋࢉΛू໿
SH 0,0(,3)
int16 t v0=*(int16 t*)addr1;
uint32 t addr2=r3;
int16 t v1=*(int16 t*)addr2;
r0=r0+(int32 t)v0-(int32 t)v1;

ਤ 9 ෳ਺ԋࢉͷࣜ΁ͷม‫׵‬
DAT1 DSECTA DS FB DS 4C
ɾɾɾ
MAIN CSECTUSING DAT1,2
MVI
A,123
MVC
B,=C’abcd’

typedef struct {int A;
char B[4];} DAT1_t;(b) ରԠදͷྫ (୅ೖจ)

˰

ΞηϯϒϦ

C ‫ޠݴ‬
CLC =’MXD’,0(R3)
BE L1
if ( strncmp( "MXD", (char*)r3, 3) == 0 ) {L1
SR 1,2
r1 = r1 - r2;}
L2
AR 1,2else {
B BB1
r1 = r1 + r2;}
BB1 ...
BB1: ;...

int main(void){((DAT1_t*) r2)->A = 123;
strncpy( ((DAT1_t*) r2)->B,"abcd", 4);
ɾ
ɾ
ɾ

ɾ
ɾ
ɾ

ਤ 10

DSECT ໋ྩͷม‫׵‬

ASM
CLC
BE

(c) ରԠදͷྫ (if จ)=C’MXD’,0(R3)
MXD

IR

ਤ 12

IR’

cc = compstr(C’MXD’, r3, 3)
BB.next = {condv=>cc, cond=>E, then=>MXD}

tmp0 = strncmp(C’MXD’, r3, 3)
tmp1 = equ32(tmp0,0)BB.next = {condv=>tmp1, cond=>NZ, then=>MXD}

C
cc = compstr("MXD", (char*) r3, 3);
if ( cc & cc_E )goto MXD;

C’
if (strncmp("MXD", (char*) r3, 3)== 0)
goto MXD;(a) ύλʔϯϚονϯάʹΑΔม‫׵‬C’MXD’ r3 3
C’MXD’ r3 3
strncmpcompstr

0

MXD

E

==

NZ

MXD

next
next

(b) ม‫׵‬ϧʔϧ

ਤ 11

උߟ

෇͚ΒΕͨ‫ݩ‬ϓϩάϥϜͷԋࢉΛࢀর͢Δ͜ͱʹΑͬͯߦ͏.
ෳ਺ͷதؒද‫͕ݱ‬ಉ͡ΞηϯϒϦͷԋࢉ΁ͷϦϯΫΛ͍࣋ͬͯ2 ࢀর), ͦͷதؒද‫͕ݱ‬શͯ C ʹม‫͞׵‬ΕͨΔ৔߹ (ਤ 12(a)࣌఺ͰΞηϯϒϦͱ C ͱͷରԠؔ܎ΛදͷΤϯτϦͱ͢Δ (ਤ212(b)).
·ͨ, ෳ਺ͷதؒද‫ݱ‬Λू໿ͯ͠ C ʹม‫ͨ͠׵‬৔߹3 ࢀর), ू໿͞Εͨதؒද‫ͱݱ‬ϦϯΫ͍ͯ͠Δશͯͷ(ਤ 12(a)
ΞηϯϒϦͷԋࢉͱ C ͱͷରԠؔ܎ΛදͷΤϯτϦͱ͢Δ (ਤ312(b)).
੍‫ߏޚ‬଄Λ࠶ߏஙͨ͠৔߹ͷॲཧ΋ಉ༷Ͱ͋Δ. ਤ 12(c) ʹ
if จΛ࠶ߏஙͨ͠৔߹ͷରԠදͷྫΛࣔ͢. ৚݅෦ͷԋࢉΛ·ͱΊ, then ෦ ͱ else ෦ͦΕͧΕʹର͠தؒද‫͔ݱ‬ΒΞηϯϒ
ϦͷԋࢉΛࢀর͢Δ͜ͱʹΑΓ, ରԠදΛ࡞੒͢Δ. do-whileจͷ৔߹΋ಉ༷ͷॲཧΛߦ͏.

5. ࣮ύλʔϯϚονϯάʹΑΔՄಡੑ޲্

ϩάϥϜʹม‫͞׵‬ΕΔ. ͜Εʹର͠, ਤ 11(b) ͷΑ͏ͳதؒද
‫ݱ‬ͷ෦෼໦ʹର͢Δม‫׵‬ϧʔϧΛద༻͢Δ͜ͱʹΑͬͯ, IR ͸
IR’ ʹม‫͞׵‬Ε, C’ ͷΑ͏ͳ C ϓϩάϥϜ͕ੜ੒͞ΕΔ.

4. ม‫׵‬աఔͷυΩϡϝϯτԽੜ੒͞Εͨ C ϓϩάϥϜʹमਖ਼͕ඞཁʹͳͬͨ৔߹ʹ͸, ΞηϯϒϦͷͲͷՕॴ͕ͲͷΑ͏ʹม‫͞׵‬Ε͔ͨͱ͍͏৘ใ͕ඇ
ৗʹॏཁʹͳΔ. ຊߘͰ͸, ΞηϯϒϦ͔Β C ϓϩάϥϜΛੜ
੒͢Δͱͱ΋ʹ, ‫ݩ‬ιʔείʔυͱੜ੒͞Εͨ C ϓϩάϥϜͷ
ରԠؔ܎Λදͷ‫Ͱܗ‬ੜ੒͢Δख๏ΛఏҊ͢Δ.
͜ͷ໨తͷͨΊʹ, தؒද‫ݱ‬ͷ֤ԋࢉʹର͠ม‫ݩ׵‬ͷΞηϯϒϦͷ໋ྩΛ‫ه‬Ա͓ͯ͘͠ (ਤ 12(a) ͷഁઢ໼ҹ). Ξηϯϒ1 ͷΑ͏ʹ
Ϧ໋ྩʹର͢Δதؒද‫͍ͳ͕ݱ‬৔߹ʹ͸, ਤ 12(a)
NOP ԋࢉΛੜ੒ͯͦ͠ͷԋࢉ΁ͷϦϯΫΛઃఆ͢Δ.
ରԠදͷੜ੒͸, தؒද‫͔ݱ‬Β C ΁ͷม‫׵‬Λߦ͏ࡍʹ, ؔ࿈ΞηϯϒϦͱ C ‫ޠݴ‬ͷରԠͷੜ੒૷ఏҊख๏ʹ‫ͮ͘ج‬γεςϜΛ Perl 5.18.4 Ͱ࣮૷ͨ͠. ಈ࡞‫ڥ؀‬͸ Ubuntu 14.04LTS, Windows Cygwin Ͱ͋Δ.
ਤ 2 ͷΞηϯϒϦϓϩάϥϜΛม‫݁ͨ͠׵‬ՌΛ ਤ 13(a) ʹࣔ͢. ΞηϯϒϦͷ 16ʙ48 ߦ໨ͷαϒϧʔνϯ EOM ͕ 30ʙ67ߦ໨ͷؔ਺ʹม‫͞׵‬Ε͍ͯΔ. ·ͨ, 34ʙ42 ߦ໨ͷ do-while
จ, 36ʙ45 ߦ໨, 48ʙ70 ߦ໨, 82ʙ89 ߦ໨ͷ if-else จͷΑ͏ʹ, ߏ଄Խ͞Εͨίʔυ͕ग़ྗ͞Ε͍ͯΔ. 54 ߦ໨Ͱ͸ෳ਺ͷԋࢉΛ·ͱΊ͓ͯΓ, ύλʔϯϚονϯάʹΑͬͯ 36, 38, 44,
46 ߦ໨ͳͲͷจࣈྻൺֱ΋ม‫͞׵‬Ε͍ͯΔ.
͜ͷϓϩάϥϜΛਤ 13(b) ʹࣔ͢ϝΠϯϓϩάϥϜͱϦϯΫ࣮ͯ͠ߦͨ݁͠Ռ, ਖ਼͘͠ಈ࡞͢Δ͜ͱ͕֬ೝͰ͖ͨ.
ຊߘͰม‫ ͨ͠׵‬C ϓϩάϥϜʹ͸, ‫͔ͭز‬ͷ੍‫͕͋ݶ‬Δ. IBMϝΠϯϑϨʔϜ͸ 32bit ϚγϯͰ͋Γ, ΞυϨεͷ֨ೲྖҬ͕
4 όΠτલఏͰ֬อ͞Ε͍ͯΔͨΊ, ม‫ ͨ͠׵‬C ϓϩάϥϜ΋
32bit ‫͔͠Ͱڥ؀‬ਖ਼͘͠ಈ࡞͠ͳ͍. ·ͨ, ϝΠϯϑϨʔϜͰ͸
EBCDIC ίʔυΛ࠾༻͍ͯ͠Δͷʹର͠, ҰൠతͳΦʔϓϯγ- 207 -

—5—εςϜͰ͸ ASCII Λ࠾༻͍ͯ͠ΔͨΊ, จࣈίʔυґଘͷॲཧ͸‫׬‬શʹ͸ม‫͍ͳ͖Ͱ׵‬. ·ͨ, EX (execute) ໋ྩͷΑ͏ʹ໋ྩͷҰ෦Λमਖ਼͢Δ΋ͷ΍, MVC (move character) ໋ྩΛ༻͍ͯଞͷ໋ྩͷҰ෦·ͨ͸શ෦Λॻ͖‫͑׵‬Δॲཧ͸ม‫͖Ͱ׵‬ͳ͍.

6. Ή ͢ ͼຊߘͰ͸, IBM ΞηϯϒϦͷ C ‫΁ޠݴ‬ͷม‫׵‬ͷࣗಈԽΛߦ͍, ͦͷม‫׵‬աఔͷυΩϡϝϯτԽΛߦ͏ख๏ΛఏҊͨ͠. SSA‫ࣜܗ‬ͷதؒද‫ʹݱ‬Մಡੑ޲্ॲཧΛద༻͢Δ͜ͱʹΑΓ, ͍͔ͭ͘ͷΞηϯϒϦϓϩάϥϜΛਖ਼͘͠ಈ࡞͢ΔՄಡੑͷߴ͍ CϓϩάϥϜʹม‫͢׵‬Δ͜ͱ͕Ͱ͖ͨ. ·ͨ, ΞηϯϒϦͱੜ੒͞Εͨ C ϓϩάϥϜͱͷରԠؔ܎Λࣔ͢දΛੜ੒͠, ม‫׵‬աఔΛυΩϡϝϯτԽ͢Δ͜ͱʹΑΓ, ΞηϯϒϦ͕ͲͷΑ͏ʹม‫͞׵‬Εͨͷ͔֬ೝ͢Δ͜ͱ͕༰қʹͳΔ.
ࠓ‫ޙ‬ͷ՝୊ͱͯ͠͸, ‫ݩ‬ϓϩάϥϜͱੜ੒͞Εͨ C ϓϩάϥϜͱͷରԠදͷੜ੒ͷ࣮૷΍, ࣮ߦ࣌ʹ໋ྩͷҙຯΛमਖ਼͢Δ
EX ໋ྩ΍ MVC ໋ྩʹΑΔίʔυͷࣗ‫΁͑׵͖ॻݾ‬ͷରԠ,
64bit ‫΁ڥ؀‬ͷରԠͳͲ͕‫͛ڍ‬ΒΕΔ.
ँࣙຊߘͷ‫ͯؔ͠ʹڀݚ‬ଟ͘ͷ‫ݴॿޚ‬Λ͍͖ͨͩ·ͨ͠‫ࣜג‬ձࣾγεςϜζͷԬຊ݈ೋࢯʹ‫͢·͍ͨ͠ँײ‬. ·ͨ, ຊ‫ؔ͠ʹڀݚ‬ͯ͝‫ྗڠ‬, ͝౼ٞ௖͍ͨؔ੢ֶӃେֶੴӜ‫ࣨڀݚ‬ͷॾࢯʹ‫ँײ‬
͍ͨ͠·͢. ຊ‫ڀݚ‬ͷҰ෦͸தখ‫ۀا‬ிฏ੒ 25 ೥౓ิਖ਼தখ‫ا‬‫ۀ‬ɾখ‫ن‬໛ࣄ‫ऀۀ‬΋ͷͮ͘Γɾ঎‫ۀ‬ɾαʔϏεֵ৽ࣄ‫ʹۀ‬ΑΔ.
จ‫ݙ‬[1] খՏ‫ོ࢙ݪ‬: “৘ใॲཧ૷ஔɺ৘ใॲཧํ๏ɺ͓ΑͼϓϩάϥϜ,”ಛ։ 2014–215938 (Nov. 2014).
[2] C. Cifuentes, M. Van Emmerik, D. Ung, D. Simon, and T.
Waddington: “Preliminary Experiences with the Use of theUQBT Binary Translation Framework,” in Proc. Workshop
on Binary Translation, pp.12–22 (Oct. 1999).
[3] M. Van Emmerik: Static Single Assignment for Decompilation, PhD Thesis, University of Queensland (2007).
[4] G. Chen, Z. Wang, R. Zhang, K. Zhou, S. Huang, K. Ni,
Z. Qi, K. Chen, and H. Guan: “A Reﬁned Decompiler toGenerate C Code with High Readability,” in Proc. Working
Conference on Reverse Engineering (WCRE), pp.150–154(Oct. 2010).
[5] Y. A. Feldman:“Portability by Automatic Translation: A
Large-Scale Case Study,” in Proc. Knowledge-Based Software Engineering Conference, pp.123–130 (Nov. 1995).
[6] M. P. Ward:“Assembler to C Migration Using the FermaTTransformation System,” in Proc. IEEE International Conference on Software Maintenance 1999 (ICSM ʟ99), pp.
67–76 (Aug.–Sept. 1999).
[7] M. P. Ward:“Reverse Engineering from Assembler to Formal Speciﬁcation via Program Transformations,” in Proc.
Working Conference on Reverse Engineering, pp. 11–20(Nov. 2000).
[8] Martin Ward:“Assembler Restructuring in FermaT,” inProc. IEEE International Working Conference on Source
Code Analysis and Manipulation (SCAM 2013), pp. 147–
156 (Sept. 2013).

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:

# include# include# include# include# include
staticstaticstaticstatic< stdio .h >< stdlib .h >< string .h >< stdint .h >" miglib . h "uint32_t r0 , r1 , r2 , r3 , r4 , r5 , r6 , r7 ;uint32_t r8 , r9 , r10 , r11 , r12 , r13 , r14 , r15 ;int cc ;char savearea [72];

int16_t MLAST [] = {0, 0,
31 , 31 ,59 , 60 ,
90 , 91 ,
120 , 121 ,
151 , 152 ,
181 , 182 ,
212 , 213 ,
243 , 244 ,
273 , 274 ,
304 , 305 ,
334 , 335 ,
365 , 366};
uint32_t SAVE [18];uint64_t WORK ;void EOMfunc ( void ) {strncpy ( ( char *) r4 , "", 8 );
r0 = 6;
r1 = r3 ;do {EOM1 : ;if ( strncmp ( ( char *) r1 , "0" , 1 ) < 0 ) { goto RET ; }else {
BB1 : ;
if ( strncmp ( ( char *) r1 , "9" , 1 ) > 0 ) { goto RET ; }else {
BB2 : ;
r1 = r1 + 1;
r0 = r0 - 1;}}
} while ( r0 ) ;BB3 : ;
if ( strncmp ( ( char *) r3 +4 , "01" , 2 ) < 0 ) { goto RET ; }else {
BB4 : ;
if ( strncmp ( ( char *) r3 +4 , "12" , 2 ) > 0 ) { goto RET ; }else {
BB5 : ;
zone_to_pack ( ( char *) & WORK , 8 , ( char *) r3 +4 , 2 ) ;r2 = pack_to_int32 ( ( char *) & WORK , 8) - 1;
BB6 : ;
r2 = ( r2 * 4) + ( uint32_t ) MLAST ;uint32_t addr27 = r2 + 4;
r0 = * ( uint16_t * ) addr27 ;int16_t tmpvar29 = * ( int16_t *) r2 ;r0 = r0 - ( int32_t ) tmpvar29 ;int32_to_pack ( ( char *) & WORK , 8 , r0 ) ;pack_to_zone ( ( char *) r4 +6 , 2 , ( char *) & WORK , 8 ) ;uint32_t addr31 = r4 + 7;
unsigned char tmp32 = * ( unsigned char *) addr31 ;unsigned char tmp33 = tmp32 & 0 x0f ;unsigned char tmp34 = tmp33 | 0 x30 ;* ( unsigned char *) addr31 = tmp34 ;strncpy ( ( char *) r4 , ( char *) r3 , 6 ) ;}}RET : ;
r15 = r15 - r15 ;return ;}int32_t EMONTH ( void ** param ) {r1 = ( uint32_t ) param ;r13 = ( uint32_t ) savearea ;r14 = ( uint32_t ) && RETURN ;EMONTHbb : ;r12 = r15 ;r15 = ( uint32_t ) SAVE ;uint32_t addr15 = r15 + 4;
* ( uint32_t *) addr15 = r13 ;uint32_t addr16 = r13 + 8;
* ( uint32_t *) addr16 = r15 ;r13 = r15 ;r3 = * ( uint32_t * ) r1 ;r4 = * ( uint32_t * ) ( r1 + 4) ;if ( strncmp (( char *) r4 , "00000000" , 6 ) ) {ER_FMT : ;abend ( 999 ) ;}else {
FC_EOM : ;EOMfunc () ;}RETURN : ;return r15 ;}(a) ਤ 2 ͷΞηϯϒϦ͔Βੜ੒͞Εͨ C ϓϩάϥϜ
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:

# include < stdio .h ># include < stdint .h ># include < string .h >int32_t EMONTH ( void ** param ) ;int main ( void ){char gdate [] = "20141215";
char result [] = "00000000";
void * param [2] = { gdate , result };int32_t rc = EMONTH ( param ) ;printf (" rc = %d , result = \"% s \"\ n " , rc , result ) ;return 0;}(b) ςετ༻ϓϩάϥϜ

ਤ 13 ੜ੒͞Εͨ C ϓϩάϥϜ

- 208 -

—6—