day 18 part 1

This commit is contained in:
Lucia Ceionia 2023-12-18 12:51:44 -06:00
parent 3362719e79
commit 5db47a3fcc
5 changed files with 1235 additions and 0 deletions

3
18/Makefile Normal file
View File

@ -0,0 +1,3 @@
all:
nasm -g -felf32 main.s && ld -melf_i386 -g main.o

784
18/input Normal file
View File

@ -0,0 +1,784 @@
R 7 (#43c232)
U 6 (#1f0fa3)
R 7 (#18f980)
D 3 (#1c5a83)
R 13 (#2a4010)
D 8 (#10ed73)
R 6 (#43c470)
D 9 (#2c1c51)
L 12 (#372130)
D 6 (#2c1c53)
L 7 (#0e8680)
D 6 (#3c7e13)
R 7 (#2f0660)
D 4 (#187de3)
R 6 (#6f1062)
D 8 (#3e68d3)
R 14 (#0b0972)
U 7 (#3b8553)
R 10 (#1bbcd2)
U 8 (#5aa601)
R 9 (#59c0b2)
U 3 (#5aa603)
L 14 (#0c14c2)
U 2 (#1b79e3)
L 4 (#322f62)
U 6 (#416201)
R 5 (#366202)
U 12 (#416203)
R 13 (#3fd0d2)
U 3 (#331943)
L 9 (#0c5f82)
U 3 (#2f0303)
R 9 (#6f6222)
U 9 (#4fd8a3)
L 11 (#15eaf0)
U 14 (#374c63)
R 11 (#0c26f0)
U 6 (#3f7353)
L 6 (#125130)
U 7 (#51dae3)
L 8 (#382b30)
D 8 (#51dae1)
L 5 (#3cd4c0)
D 6 (#1a2ea3)
L 11 (#251d90)
D 14 (#0842b3)
L 5 (#55c8c0)
U 3 (#58dea3)
L 8 (#0b7bb0)
U 11 (#5b3af3)
L 4 (#382100)
U 9 (#47fe13)
L 6 (#01b2e0)
U 5 (#4e82f3)
L 7 (#6e3740)
U 14 (#1cb493)
R 9 (#2c13e2)
U 9 (#206be3)
R 2 (#422362)
U 8 (#3bcfb3)
R 9 (#35b660)
U 7 (#37b1c3)
R 5 (#0d2980)
U 5 (#38fae3)
R 9 (#33e870)
U 10 (#403e11)
R 8 (#400260)
D 6 (#225021)
L 5 (#716760)
D 7 (#0e1e71)
R 5 (#287120)
D 9 (#5a71b1)
R 4 (#015c40)
U 10 (#6d0161)
R 6 (#06ed20)
D 8 (#602ca3)
R 7 (#3ddc50)
D 5 (#1adef3)
L 4 (#51eca0)
D 4 (#1adef1)
L 8 (#167b90)
U 4 (#3c7553)
L 5 (#3651e0)
D 7 (#0ce671)
R 17 (#26fae0)
D 5 (#0ce673)
L 7 (#2216b0)
D 5 (#1ac753)
R 13 (#2585f0)
U 10 (#05c323)
R 4 (#6a5190)
D 4 (#0c9913)
R 4 (#53e6e0)
D 10 (#239103)
L 4 (#1a0b82)
D 4 (#217593)
R 7 (#117862)
U 8 (#0efd13)
R 11 (#3b6432)
U 7 (#0efd11)
L 11 (#449482)
U 3 (#4b4ab3)
R 7 (#400530)
U 7 (#093f03)
L 16 (#516be0)
U 8 (#529313)
L 2 (#1a0b80)
U 5 (#49b4e3)
R 13 (#388aa0)
U 11 (#268b13)
R 3 (#3ed060)
U 10 (#525fd1)
R 7 (#2dee20)
U 14 (#525fd3)
R 4 (#1c7120)
U 4 (#4b5dc3)
R 6 (#071870)
U 3 (#16bc91)
R 6 (#0f7ea0)
D 4 (#3c3a83)
R 5 (#40a2f0)
U 4 (#3c3a81)
R 8 (#322d90)
D 2 (#16bc93)
R 7 (#1a45b0)
D 3 (#0dda01)
R 2 (#002990)
D 14 (#3ce0a1)
R 6 (#09b080)
D 2 (#3f3411)
R 6 (#712ba0)
U 4 (#18fc01)
R 4 (#50ae42)
U 14 (#394c81)
L 8 (#5992d2)
U 9 (#2c5181)
R 8 (#485892)
U 5 (#304b41)
L 6 (#671760)
U 11 (#3b2833)
L 10 (#349250)
U 10 (#3b2831)
L 9 (#1fea10)
U 6 (#5a4581)
L 8 (#3705e0)
D 7 (#2140a1)
L 6 (#3e1360)
U 7 (#51bce1)
L 7 (#61f190)
U 2 (#105a71)
L 6 (#2f41f0)
U 7 (#2eb5a1)
L 8 (#6a2b10)
U 3 (#103f93)
L 8 (#358c70)
U 5 (#103f91)
L 4 (#44e3e0)
U 12 (#2eb5a3)
L 11 (#1d4ef0)
U 9 (#621753)
L 4 (#0a1d50)
U 4 (#249d51)
R 4 (#287d90)
U 12 (#539513)
L 13 (#4e0190)
U 3 (#539511)
R 9 (#2ff870)
U 5 (#47b5b1)
R 7 (#385e80)
D 6 (#319f31)
R 5 (#247600)
D 7 (#0546b1)
R 16 (#4ee172)
D 4 (#163921)
L 16 (#006a42)
D 9 (#5c7f61)
R 6 (#4f4bb0)
D 2 (#09d9f1)
R 12 (#2da090)
U 3 (#38a4a3)
R 6 (#233670)
U 12 (#411713)
R 7 (#44f222)
U 13 (#5936f3)
R 9 (#0846c2)
D 5 (#2495a3)
R 8 (#4d38e0)
U 8 (#284313)
R 2 (#004360)
U 9 (#591641)
R 9 (#249b10)
U 15 (#5dbd81)
R 10 (#542730)
D 12 (#0658a1)
R 8 (#202200)
D 13 (#63e481)
R 7 (#417100)
D 11 (#115831)
R 3 (#1308a0)
D 8 (#5d7591)
R 4 (#5bbe90)
U 7 (#1dc0a3)
R 5 (#051c50)
U 17 (#510d23)
R 3 (#2322f0)
D 15 (#020aa3)
R 6 (#47ea42)
D 9 (#09f123)
R 7 (#130062)
D 12 (#1a0523)
L 6 (#4a2022)
D 4 (#473b73)
L 6 (#6dfee0)
D 4 (#24c393)
L 7 (#6dfee2)
U 4 (#2cbcb3)
L 6 (#137852)
U 4 (#57d193)
L 8 (#2c6570)
D 9 (#2c2113)
L 5 (#30de90)
D 8 (#298141)
L 10 (#286a40)
D 2 (#298143)
R 10 (#2c7790)
D 8 (#2c2111)
L 4 (#065d40)
D 11 (#0ded33)
R 14 (#5189c0)
U 11 (#125f21)
R 7 (#183960)
U 10 (#280071)
R 3 (#1fe640)
D 5 (#2c8b81)
R 7 (#504d70)
D 9 (#532921)
R 4 (#03e252)
D 7 (#169441)
R 7 (#3d6792)
D 14 (#278961)
L 4 (#472332)
D 9 (#2c4981)
R 8 (#2df3a0)
D 5 (#2ca501)
R 13 (#06f2d0)
D 3 (#479821)
L 10 (#06f2d2)
D 14 (#0916f1)
L 4 (#3a21d0)
D 6 (#342e23)
L 7 (#143d52)
D 10 (#3de0a3)
R 4 (#143d50)
D 7 (#0b4553)
R 6 (#3578d0)
D 4 (#454381)
R 8 (#12b310)
D 15 (#5c55a1)
R 3 (#400ad2)
D 15 (#708e81)
R 4 (#44a4e2)
D 3 (#195891)
R 11 (#40cec2)
D 14 (#0bf6f1)
R 9 (#3f7c42)
D 7 (#44f361)
L 14 (#252c20)
D 7 (#219561)
R 14 (#252c22)
D 5 (#3b93f1)
R 5 (#3f7c40)
D 4 (#1b4631)
R 7 (#5a10e2)
U 10 (#403fe3)
L 6 (#1c0942)
U 5 (#166bd3)
R 6 (#0dfeb2)
U 10 (#2faa13)
R 9 (#442662)
D 11 (#430413)
R 5 (#24e8f2)
D 10 (#254ae1)
L 5 (#698c32)
D 4 (#450431)
R 10 (#698c30)
U 8 (#19b101)
R 7 (#280ab2)
U 3 (#207b01)
R 8 (#1056d2)
U 4 (#0188c1)
R 9 (#566192)
U 8 (#153a81)
R 8 (#0ff8a2)
D 12 (#50b171)
R 10 (#0611d2)
D 11 (#168a11)
R 11 (#0ac2c0)
D 8 (#27c361)
L 5 (#49f630)
D 17 (#27c363)
R 5 (#2809e0)
D 12 (#08f281)
R 8 (#5d4ed0)
D 5 (#60c0b3)
R 3 (#1281e0)
U 4 (#4ee241)
R 7 (#627020)
U 7 (#4ee243)
R 8 (#4cdbc0)
U 7 (#60c0b1)
R 7 (#425e30)
D 6 (#059533)
R 4 (#259d90)
D 12 (#059531)
R 8 (#5398f0)
D 5 (#0f94a1)
R 6 (#1f6202)
U 6 (#118ec1)
R 7 (#584412)
D 6 (#633d01)
R 8 (#15f142)
D 8 (#30fcf1)
R 3 (#545932)
D 7 (#2e3d11)
L 3 (#0e4c62)
D 15 (#029c53)
L 6 (#1c5592)
D 3 (#3d4a43)
R 2 (#139220)
D 3 (#526013)
R 5 (#139222)
D 11 (#12bd03)
R 11 (#3955d2)
D 7 (#2f0223)
R 7 (#301b12)
D 5 (#0639e3)
R 12 (#2dbde2)
D 7 (#0639e1)
L 15 (#368152)
D 3 (#035551)
L 4 (#504f00)
D 12 (#4daf51)
R 7 (#09a6a0)
D 4 (#4ade31)
L 8 (#5b7570)
D 12 (#2a8671)
L 10 (#0291f0)
D 2 (#0f4cd1)
L 7 (#6f41f0)
D 16 (#4c29f1)
L 9 (#135550)
D 7 (#227161)
L 11 (#0e4ab2)
D 12 (#5b4aa1)
L 6 (#3d25f2)
D 6 (#5b4aa3)
L 7 (#40ef22)
D 4 (#3c2521)
L 9 (#018b52)
U 7 (#19e481)
L 5 (#47bbf2)
U 7 (#088601)
L 10 (#21bf60)
U 6 (#3c1c71)
L 6 (#21bf62)
U 7 (#3df0a1)
L 11 (#45d380)
U 7 (#23fff1)
R 10 (#455c50)
U 4 (#2d4481)
R 7 (#4a7730)
D 4 (#20be61)
R 10 (#032890)
U 10 (#66a6e3)
L 6 (#174410)
U 12 (#31a043)
L 5 (#302140)
U 12 (#5240c1)
L 8 (#43c1e0)
U 11 (#5240c3)
L 6 (#498ad0)
U 12 (#31a041)
L 4 (#0612a0)
U 4 (#4cc393)
L 2 (#416240)
U 6 (#3f9c83)
L 4 (#6624a2)
U 6 (#2f4df3)
L 11 (#233af2)
U 7 (#67d713)
L 8 (#219562)
D 4 (#191fd3)
L 11 (#425670)
D 7 (#2f9aa1)
L 9 (#5826b0)
D 5 (#2f9aa3)
L 9 (#02b510)
D 5 (#1eee93)
L 7 (#0dc2c0)
D 9 (#5e5973)
R 7 (#3a3e70)
D 5 (#1a55b3)
L 3 (#5bc130)
D 11 (#3c03a3)
L 7 (#2add40)
D 8 (#2fd5e3)
L 7 (#140162)
D 8 (#11daa3)
L 8 (#5d1932)
D 11 (#11daa1)
L 9 (#1583e2)
D 8 (#4b35b3)
L 9 (#742210)
D 2 (#2cb393)
L 13 (#275e80)
U 3 (#5989e1)
L 5 (#04e2c2)
U 11 (#2865a1)
R 5 (#04e2c0)
U 13 (#7c28f1)
R 5 (#338d60)
U 3 (#6cb1a1)
R 3 (#33f4c0)
U 4 (#19a1a1)
L 13 (#404cc0)
U 3 (#4671a1)
L 4 (#467420)
D 14 (#4e3051)
L 11 (#2653e2)
D 5 (#2d21d1)
L 4 (#3fe972)
D 9 (#2d21d3)
L 6 (#547852)
D 9 (#523421)
L 8 (#61db40)
D 17 (#093c71)
L 7 (#013960)
D 9 (#5341d1)
L 11 (#137f70)
D 12 (#1f9541)
L 2 (#43d170)
D 3 (#3756f1)
R 2 (#1460c0)
D 16 (#5f6ae1)
R 3 (#3d9e12)
D 13 (#0e0541)
R 10 (#290712)
D 7 (#244a91)
R 3 (#08f492)
U 14 (#50e851)
R 9 (#319750)
U 6 (#50cce1)
R 9 (#3e0260)
D 6 (#133501)
R 4 (#3e7640)
U 4 (#5b11d1)
R 13 (#18ca50)
U 9 (#1bde41)
R 8 (#2f7fe0)
U 10 (#1d8fa1)
R 3 (#013520)
U 3 (#4a1001)
R 3 (#005960)
U 9 (#41de93)
R 10 (#5ac660)
U 7 (#25c113)
R 3 (#4a0ae0)
D 3 (#57bd11)
R 14 (#186ec2)
D 11 (#363301)
L 14 (#6f3c92)
D 5 (#30d021)
R 10 (#0b4520)
D 4 (#37c321)
R 5 (#64e710)
D 6 (#37c323)
R 8 (#352280)
D 13 (#3e6021)
R 5 (#023060)
D 3 (#34b0e1)
L 9 (#1134f2)
D 4 (#5ef331)
L 9 (#1a4052)
D 3 (#274471)
R 3 (#333bd2)
D 8 (#1e38a3)
R 12 (#3462b2)
D 4 (#67ff03)
R 3 (#146b52)
D 7 (#224ba1)
R 10 (#099452)
D 9 (#076ef1)
R 9 (#406312)
D 2 (#54eda1)
R 10 (#0fae42)
D 9 (#74d4a1)
L 4 (#220d72)
D 8 (#0b6731)
L 15 (#314cb2)
D 3 (#2541f1)
L 9 (#061062)
D 8 (#65c091)
L 8 (#220c02)
D 13 (#0e5b01)
L 11 (#4f0f62)
D 10 (#469d91)
L 14 (#31c612)
U 8 (#406ec1)
L 16 (#382f52)
U 5 (#479c53)
L 13 (#548c72)
U 8 (#4005f3)
L 9 (#610822)
U 2 (#02cfd3)
L 9 (#0d4c22)
U 4 (#4f4793)
L 5 (#2291b2)
U 7 (#53adc3)
R 6 (#3a5872)
U 4 (#25eaf3)
R 9 (#3dc5e0)
D 4 (#4cf953)
R 8 (#1e7810)
U 6 (#2fec63)
L 4 (#0c79f0)
U 10 (#144493)
L 8 (#39b740)
U 10 (#144491)
L 6 (#3a0830)
U 7 (#2c4793)
L 5 (#4213d2)
D 10 (#4aa983)
L 4 (#24f902)
D 8 (#3f1823)
L 6 (#4802f2)
D 8 (#253191)
L 3 (#19c2c2)
D 6 (#2818e1)
L 7 (#19c2c0)
D 16 (#3c7731)
R 7 (#2d6792)
D 6 (#4ef903)
R 4 (#336e42)
D 4 (#238ec3)
L 4 (#4ac572)
D 9 (#5427a3)
L 9 (#053882)
D 8 (#6bf101)
L 2 (#42c482)
D 16 (#044bf1)
L 3 (#1461c2)
U 12 (#0502c1)
L 8 (#74a2e2)
U 11 (#0502c3)
L 4 (#3e7212)
D 4 (#2bd771)
L 13 (#141c02)
D 5 (#6061d1)
L 3 (#5ca8e2)
D 8 (#04a951)
R 9 (#2b1342)
D 9 (#671121)
L 9 (#33afb2)
D 8 (#1eb701)
L 12 (#4db550)
U 7 (#609eb1)
R 8 (#4db552)
U 15 (#10ae91)
L 8 (#2b2572)
U 8 (#25c4f1)
L 8 (#605e82)
U 4 (#09af31)
L 9 (#4328a2)
U 9 (#09af33)
L 17 (#21d142)
U 2 (#11e5f1)
R 17 (#263f50)
U 9 (#152301)
R 7 (#18b880)
U 8 (#014a31)
R 5 (#42b160)
U 14 (#17c201)
R 7 (#5d7500)
D 7 (#17c203)
R 10 (#23e090)
D 10 (#014a33)
R 12 (#0a5140)
U 14 (#152303)
R 3 (#55f650)
U 3 (#1c1ec1)
R 9 (#3aec42)
U 6 (#03e4b1)
R 3 (#45b7a2)
U 10 (#5ce301)
L 10 (#223d12)
U 13 (#2330d1)
L 13 (#74b632)
U 9 (#411551)
L 7 (#22caa2)
D 5 (#429fb1)
L 6 (#28e492)
D 14 (#4b6a41)
L 5 (#60a302)
D 3 (#05e403)
L 3 (#70cdf2)
U 9 (#05e4a1)
L 3 (#004a12)
U 11 (#6ebca1)
L 9 (#2f5d62)
U 4 (#51e5e3)
L 9 (#33ef12)
U 13 (#22bb63)
L 9 (#400e42)
U 6 (#4e0bc3)
L 10 (#2efb82)
U 11 (#320cc3)
L 5 (#3f8372)
U 3 (#529693)
L 9 (#305d52)
U 3 (#356f73)
L 5 (#068d72)
U 7 (#7321f1)
R 5 (#46e4b2)
U 4 (#7321f3)
R 5 (#32a3a2)
D 11 (#4b2fe3)
R 5 (#20bd80)
U 11 (#65e3a3)
R 8 (#3b3e40)
U 6 (#139783)
L 15 (#7a1050)
U 9 (#139781)
L 8 (#3ad500)
U 11 (#1fc253)
L 3 (#0e10f0)
U 9 (#580d53)
L 4 (#195782)
U 8 (#170a13)
L 7 (#1cc302)
U 2 (#4641b1)
L 6 (#4ec5c2)
U 10 (#492003)
L 11 (#43f2e2)
U 3 (#754983)
L 5 (#47df02)
U 6 (#754981)
L 9 (#0b6ed2)
U 5 (#492001)
R 9 (#0fb482)
U 8 (#6c73c1)
R 5 (#2d8f52)
U 3 (#23de61)
L 8 (#325f00)
D 3 (#53e8e1)
L 6 (#325f02)
D 3 (#3715c1)
L 4 (#433092)
D 14 (#40d3b1)
R 10 (#681512)
D 3 (#57d843)
L 7 (#1af362)
D 4 (#107e23)
L 6 (#545a32)
D 12 (#4e9023)
L 6 (#0ff9f2)
D 8 (#4b29b3)
L 3 (#484e52)
D 8 (#0a1063)
L 15 (#32d802)
D 7 (#5003e3)
L 4 (#213d02)
D 11 (#190461)
L 2 (#357f92)
D 6 (#6b8611)
L 10 (#3990e0)
D 5 (#077dd1)
L 4 (#426220)
D 11 (#6536c1)
L 8 (#18d540)
U 11 (#034201)
L 8 (#5b3762)
D 3 (#0fa911)
L 3 (#3990e2)
U 6 (#21be11)
L 14 (#59c742)
U 6 (#384881)
L 4 (#4ebc42)
U 8 (#5ed321)
L 4 (#4ebc40)
U 12 (#1a8f21)
L 3 (#504172)
U 5 (#042cd3)
L 11 (#3913b2)
U 4 (#77f953)
R 14 (#328612)
U 9 (#0d33d3)
R 3 (#20be92)
U 3 (#377b23)
R 10 (#20be90)
U 10 (#439383)
R 4 (#156e80)
U 14 (#12bf53)
R 5 (#562b40)
U 10 (#220b93)
L 5 (#1c3732)
U 3 (#46b0d3)
R 9 (#03f4c2)
U 9 (#165873)
L 9 (#12b652)
U 6 (#4737a3)
L 6 (#3bae72)
U 2 (#4ca8b3)
L 11 (#422bc2)
D 7 (#4ca8b1)
R 4 (#090d02)
D 9 (#406043)
R 9 (#091222)
D 6 (#2fd4c3)
L 7 (#0e6352)
D 3 (#42d653)
L 6 (#4aa522)
D 13 (#287113)
L 7 (#145852)
U 5 (#4a75c1)
L 7 (#640962)
U 15 (#4a75c3)
R 7 (#506322)
U 10 (#482373)
L 11 (#75df22)
U 8 (#369ab3)
L 8 (#75df20)
U 11 (#390283)
R 7 (#52b932)
U 4 (#508653)
R 5 (#46bbc0)
U 11 (#56d983)
R 6 (#64efe0)
U 10 (#1482b3)
R 7 (#3d20d0)
D 6 (#1dad03)
R 4 (#5fb9f0)
D 7 (#490903)
L 4 (#2c0010)
D 12 (#662ae3)
R 3 (#30a052)
U 8 (#64f5f3)
R 15 (#30a050)
U 5 (#650093)
R 12 (#5a5bd2)
U 4 (#2b5033)
R 3 (#3a86c2)
D 7 (#5d1e83)
R 7 (#218372)
D 11 (#0bc483)
R 7 (#0dcaf2)
U 3 (#2d2f93)
L 4 (#653610)
U 11 (#422573)
R 4 (#653612)
U 4 (#479223)
R 3 (#0dcaf0)
D 8 (#202b53)
R 10 (#4f8ea0)
D 3 (#210eb3)
R 14 (#4f8ea2)
D 9 (#3c44b3)
R 12 (#458112)
U 9 (#12cf91)
R 8 (#413da2)
U 11 (#036641)
R 5 (#4e1fe0)
D 4 (#465131)
R 12 (#01c8c0)
U 4 (#2aa881)
R 10 (#4fe8a2)
U 3 (#341941)
R 6 (#55c252)
U 13 (#339dc3)
R 5 (#449340)
U 7 (#566e43)
R 3 (#449342)
U 10 (#313cc3)
L 10 (#1e28f2)
U 9 (#09d973)

14
18/input_test Normal file
View File

@ -0,0 +1,14 @@
R 6 (#70c710)
D 5 (#0dc571)
L 2 (#5713f0)
D 2 (#d2c081)
R 2 (#59c680)
D 2 (#411b91)
L 5 (#8ceee2)
U 2 (#caa173)
L 1 (#1b58a2)
U 2 (#caa171)
R 2 (#7807d2)
U 3 (#a77fa3)
L 2 (#015232)
U 2 (#7a21e3)

149
18/main.s Normal file
View File

@ -0,0 +1,149 @@
%include "utils.s"
global _start
[bits 32]
[section .text]
%define FILENAME "input"
;%define FILENAME "input_test"
;%define PRINT
_start:
mov esi, file
mov edi, array+1024*512+512 ; like, the middle idk
mov byte [edi], 1 ; filled!
proc_line:
cmp esi, file.over
jae .done
lodsb ; RDLU
%ifdef PRINT
call print_char
call space
%endif
mov ebx, eax
inc esi ; space
call dec_parse ; count
%ifdef PRINT
call print_dec
call newline
%endif
; skip to next line
add esi, 10
; put in array
cmp bl, 'R'
mov ecx, 1
cmove edx, ecx
cmp bl, 'L'
mov ecx, -1
cmove edx, ecx
cmp bl, 'D'
mov ecx, 1024
cmove edx, ecx
cmp bl, 'U'
mov ecx, -1024
cmove edx, ecx
mov ecx, eax
.draw:
add edi, edx
mov byte [edi], 1
loop .draw
jmp proc_line
.done:
%ifdef PRINT
print_array:
call newline
mov esi, array
xor ecx, ecx
.inner:
mov bl, '.'
lodsb
test al, al
mov dl, '#'
cmovnz bx, dx
mov al, bl
call print_char
inc ecx
cmp ecx, 1024*1024
jae .done
mov ebx, ecx
and ebx, 1023
jnz .inner
call newline
jmp .inner
.done:
call newline
%endif
xor ecx, ecx ; x = 0
xor ebx, ebx ; y = 0
mov ebp, 1024*1024 ; count
call flood_fill
jmp flood_done
flood_fill:
mov eax, ebx
shl eax, 10
cmp byte [array+eax+ecx], 0
je .zero
ret
.zero:
dec ebp
mov byte [array+eax+ecx], 1
sub esp, 8
mov [esp+4], ecx
mov [esp+0], ebx
.t_right:
cmp ecx, 1023
je .t_left
inc ecx
call flood_fill
mov ecx, [esp+4]
.t_left:
cmp ecx, 0
je .t_down
dec ecx
call flood_fill
mov ecx, [esp+4]
.t_down:
cmp ebx, 1023
je .t_up
inc ebx
call flood_fill
mov ebx, [esp+0]
.t_up:
cmp ebx, 0
je .ret
dec ebx
call flood_fill
mov ebx, [esp+0]
.ret:
add esp, 8
ret
flood_done:
mov [final_value], ebp
game_over:
mov eax, [final_value]
call print_dec
call newline
jmp exit
PANIC:
p_string panic_str
jmp exit
[section .data]
final_value: dd 0
file: incbin FILENAME
.over:
[section .bss]
array: resb 1024*1024
[section .rodata]
panic_str: db 10, "AAAAAAAAAAAAAAAAAAAAAA!!!!!!!!!!11111111", 10
.over:

285
18/utils.s Normal file
View File

@ -0,0 +1,285 @@
[bits 32]
[section .text]
; call # val val2
; int $0x80 eax eax edx -
;
; arg1 arg2 arg3 arg4 arg5 arg6 arg7
; ebx ecx edx esi edi ebp -
exit:
mov eax, 1 ; exit
int 0x80
; filename in EBX
; return handle in EBX
; read only
open_file:
push eax
push ecx
mov eax, 5 ; open
xor ecx, ecx ; read only
int 0x80
mov ebx, eax
pop ecx
pop eax
ret
; file handle in EBX
; buffer in ECX
; count of bytes to read in EDX
; return bytes actually read in EAX
; exits on error
read_file:
mov eax, 3 ; read
int 0x80
test eax, eax
js .err
ret
.err:
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, .err_str
mov edx, 21
int 0x80
jmp exit
.err_str: db `Could not read file.\n`
; string input in ESI
; value in EAX
; CF set if none, clear if some
; ESI set past checked area
dec_parse:
push ebx
push edx
push edi
xor eax, eax
xor edi, edi
mov ebx, 10 ; base
lodsb
sub al, '0'
js .no_input
cmp al, 9
jle .got_char
.no_input:
stc ; set CF
jmp .done
.loop:
xor eax,eax
lodsb
sub al, '0'
js .dec_done
cmp al, 9
jg .dec_done
.got_char:
xchg edi,eax
mul ebx
add edi,eax
jmp .loop
.dec_done:
clc ; clear CF
.done:
mov eax,edi
pop edi
pop edx
pop ebx
ret
; string input in ESI
; value in EAX
; CF set if none, clear if some
; ESI set past checked area
sign_dec_parse:
push ebx
push ecx
push edx
push edi
xor eax, eax
xor edi, edi
xor ecx, ecx ; neg flag
mov ebx, 10 ; base
cmp byte [esi], '-'
jne .no_minus
inc esi
mov cl, 1
.no_minus:
lodsb
sub al, '0'
js .no_input
cmp al, 9
jle .got_char
.no_input:
stc ; set CF
jmp .done
.loop:
xor eax,eax
lodsb
sub al, '0'
js .dec_done
cmp al, 9
jg .dec_done
.got_char:
xchg edi,eax
mul ebx
add edi,eax
jmp .loop
.dec_done:
test ecx, ecx
jz .not_neg
neg edi
.not_neg:
clc ; clear CF
.done:
mov eax,edi
pop edi
pop edx
pop ecx
pop ebx
ret
; modifies no regs
newline:
pushad
push 10
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, esp ; string
mov edx, 1 ; length
int 0x80
add esp, 4
popad
ret
; modifies no regs
space:
pushad
push 9
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov ecx, esp ; string
mov edx, 1 ; length
int 0x80
add esp, 4
popad
ret
; input in EAX, all regs unmodified
print_dec:
pushad ; save regs
; max 4294967296 is 10 chars
; round to nearest 32-bit boundary
sub esp, 12
; string in ECX, length in EDX
lea ecx, [esp+11] ; last possible byte
; check for 0
test eax, eax
jz .zero
mov ebx, 10 ; base 10
xor esi, esi ; counter
.div_shit:
xor edx, edx
; divide
div ebx
dec ecx ; next char
inc esi
; store
add dl, '0'
mov byte [ecx], dl
; check if done
test eax, eax
jnz .div_shit ; continue
mov edx, esi ; counter in edx
jmp .write
.zero:
mov byte [ecx], '0'
mov edx, 1 ; length
.write:
mov eax, 4 ; write
mov ebx, 1 ; stdout
int 0x80
add esp, 12 ; restore stack
popad ; restore regs
ret
; input in EAX, all regs unmodified
print_sign_dec:
pushad ; save regs
; range -2147483648 to 2147483647 is 11 chars
; round to nearest 32-bit boundary
sub esp, 12
; string in ECX, length in EDX
lea ecx, [esp+11] ; last possible byte
; check for 0, negative
xor ebp, ebp
test eax, eax
jz .zero
jns .positive
neg eax
mov ebp, 1
.positive:
mov ebx, 10 ; base 10
xor esi, esi ; counter
.div_shit:
xor edx, edx
; divide
div ebx
dec ecx ; next char
inc esi
; store
add dl, '0'
mov byte [ecx], dl
; check if done
test eax, eax
jnz .div_shit ; continue
mov edx, esi ; counter in edx
jmp .write
.zero:
mov byte [ecx], '0'
mov edx, 1 ; length
.write:
test ebp, ebp
jz .no_minus
dec ecx
inc edx
mov byte [ecx], '-'
.no_minus:
mov eax, 4 ; write
mov ebx, 1 ; stdout
int 0x80
add esp, 12 ; restore stack
popad ; restore regs
ret
; input in ESI, len in ECX, all regs unmodified
print_string:
pushad ; save regs
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov edx, ecx ; length
mov ecx, esi ; string
int 0x80
popad ; restore regs
ret
; input in AL, all regs unmodified
print_char:
pushad ; save regs
push eax
mov eax, 4 ; write
mov ebx, 1 ; stdout
mov edx, 1 ; length
mov ecx, esp ; string
int 0x80
add esp, 4
popad ; restore regs
ret
; --- MACROS ---
%define len(x) x %+ .over - x
%macro p_string 1
push esi
push ecx
mov esi, %1
mov ecx, len(%1)
call print_string
pop ecx
pop esi
%endmacro