{"video_id":"665rzOSSxWA","comment_count":400,"fetched_at":"2026-10-20T17:05:32+00:00","source":"innertube_next","comments":[{"id":"UgyKSncBdPsNdD792dx4AaABAg","text":"As someone who subscribes to a ton of tech-related channels, this is the first time YouTube recommended me to this channel.","author":"@chyldstudios","author_id":"UCoxgRBEk_fIKnlg_Qx8ughQ","like_count":396,"published_time":"2 years ago"},{"id":"Ugyt6Z4xGrMspdGvyKx4AaABAg","text":"Easily the greatest common divisor in the history of all common divisors","author":"@maisylover","author_id":"UCO_UB8B3SZ2M0uPZ0gp9aKQ","like_count":252,"published_time":"2 years ago"},{"id":"Ugx2A2jKZ5xI6NegQyl4AaABAg","text":"I was looking for something to snooze to and thought this was ASMR Assembly.","author":"@maelstrom57","author_id":"UC9BJqAqRlOJBAA0O4WYSmnw","like_count":77,"published_time":"2 years ago"},{"id":"UgxEwA0HYsWpnm94ol14AaABAg","text":"This is a great introduction and walk through for newcomers to assembly, but beware that the implementation has a quite significant flaw that will only reveal itself when called from other functions that have several live registers and happen to use r4 and store a value in it when it makes the call to this gcd function. The calling function will expect that the gcd function preserves the r4 register, as it is not a scratch register like r0-r3 are. This will manifest in miscalculations, unpredictable behavior and likely instability/crashes in the application using this function. An easy fix would be to push the r4 register along with lr to the stack, and pop it again (i.e. push {r4, lr} - pop {r4, pc}), but this of course increases the stack usage even more. Another approach would be to use r12 which is also a scratch register.\n\nIt would also be a good idea to make the implementation non-recursive as it can overflow the stack if it recurses too many times. For this algorithm this is quite easy as you can do tail call optimization by simply removing the push, replacing the pop by \"bx lr\" and doing a \"b gcd\" instead of \"bl gcd\" (which means the lr does not get overwritten for each iteration and retains the original return address that was written when the function was called the first time). This means the stack won't grow for each iteration.","author":"@ThomasThorsen","author_id":"UCrnn5DYsdOmhT13aXqqsUUg","like_count":97,"published_time":"2 years ago"},{"id":"UgxdFqs0p_Ow9Y27LQp4AaABAg","text":"What matrix movie is this girl in the red dress clip taken from? subscribed","author":"@BombadilHillStudios","author_id":"UCWxUfOOYZDnSfwFn-m1MF6A","like_count":0,"published_time":"2 years ago (edited)"},{"id":"Ugz0l1hff5kaxjPVfNB4AaABAg","text":"is that actually your voice","author":"@dsrtsnw","author_id":"UCUPJ5YHYgTPHPerqzzojaUA","like_count":0,"published_time":"2 years ago"},{"id":"Ugw27_euMbyHqSl2tzB4AaABAg","text":"Yeah, no one came here for coding.","author":"@steadystreamofserotonin5500","author_id":"UCyiLAux8w3RBnsBWumOhUDw","like_count":1,"published_time":"2 years ago"},{"id":"UgyUjaWQwyqe_HXIJUx4AaABAg","text":"LETS ALL LOVE LAIN","author":"@automata-mw2el","author_id":"UCpCT1s761ey82nnry41LGbA","like_count":0,"published_time":"2 years ago"},{"id":"Ugw-NpnYqzzgUJNQFK14AaABAg","text":"+1 subscriber. This is awesome!","author":"@Alberto_Cavalcante","author_id":"UCTtw8PLImNhOu0NYD5R9bww","like_count":0,"published_time":"2 years ago"},{"id":"UgxsQv_7fH884QsIYhx4AaABAg","text":"Assembler It is the easiest language to learn if you hard a difficult challenge learn in deep c++.","author":"@jesusje1199","author_id":"UCYWqtKXJRsrv-9z4UcOGc8g","like_count":0,"published_time":"2 years ago"},{"id":"UgyKJg4O75tox4bfZxZ4AaABAg","text":"This is so good! Your attention to detail is insane! Congrats","author":"@tom_verlaine_again","author_id":"UCIb6XBkXP-w4hL1YOSo-NQQ","like_count":0,"published_time":"2 years ago"},{"id":"Ugyrkz653RIemsgNUYN4AaABAg","text":"Great Video!","author":"@chrisblevins4502","author_id":"UCwRaEn85V-3O7t4BR2Z_bow","like_count":0,"published_time":"2 years ago"},{"id":"Ugx7yzwH-caRy5-qquR4AaABAg","text":"Love the Windows XP theme lol. Shout out to the greatest OS Microsoft ever made.","author":"@Noisy_Cricket","author_id":"UC9Yz-Nmt_E7tU2-1-mI-xVw","like_count":0,"published_time":"2 years ago"},{"id":"UgyVu7wr2Ap24hNytQR4AaABAg","text":"nerd","author":"@do0rkn0b","author_id":"UCSD1hjKuRZwQ7-JiSINrlYg","like_count":0,"published_time":"2 years ago"},{"id":"UgyEEwnjtyxBAB9xiI94AaABAg","text":"Incredible production quality!","author":"@Veynney","author_id":"UCcHLOYkj-0I9zHUt7_vipUA","like_count":1,"published_time":"2 years ago"},{"id":"UgwZ9-JliDewku8Jq2t4AaABAg","text":"the keyboard sound directly transfers to the microphone standing on the desktop. that is not optimal. the microphone should stand separately (mic stand) i.m.h.o.","author":"@hartmut-a9dt","author_id":"UCmmWEvsFeY07Y57y9nxeE6A","like_count":0,"published_time":"2 years ago"},{"id":"UgxWyrKS3hlIhvfiPUN4AaABAg","text":"NO WAY","author":"@sergei8337","author_id":"UCWlEYW16hx_CMJ6kO7Rx_gQ","like_count":0,"published_time":"2 years ago"},{"id":"Ugwr7lZDKTwVMY78e6Z4AaABAg","text":"Only 27k subscribers? Deserves way more","author":"@heinrichpreussen","author_id":"UCalVJp_-56Y3GuJiw35CR0Q","like_count":0,"published_time":"2 years ago"},{"id":"Ugx9B__mOp-_U-W1izV4AaABAg","text":"I am so confused, how did I end up here?","author":"@int2kk","author_id":"UCl-WRqlLXpXaO0pLG3aZ6sQ","like_count":0,"published_time":"2 years ago"},{"id":"Ugwz5gUitMd9c03bxnZ4AaABAg","text":"why not just compile the c","author":"@ArrrPG","author_id":"UCE2ruR-agDDo2tWQB80hftA","like_count":0,"published_time":"2 years ago"},{"id":"Ugyt6Z4xGrMspdGvyKx4AaABAg","text":"Easily the greatest common divisor in the history of all common divisors","author":"@maisylover","author_id":"UCO_UB8B3SZ2M0uPZ0gp9aKQ","like_count":252,"published_time":"2 years ago"},{"id":"Ugx2A2jKZ5xI6NegQyl4AaABAg","text":"I was looking for something to snooze to and thought this was ASMR Assembly.","author":"@maelstrom57","author_id":"UC9BJqAqRlOJBAA0O4WYSmnw","like_count":77,"published_time":"2 years ago"},{"id":"UgyKSncBdPsNdD792dx4AaABAg","text":"As someone who subscribes to a ton of tech-related channels, this is the first time YouTube recommended me to this channel.","author":"@chyldstudios","author_id":"UCoxgRBEk_fIKnlg_Qx8ughQ","like_count":396,"published_time":"2 years ago"},{"id":"Ugyfje5VGCaYkZjTujR4AaABAg","text":"I feel like Laurie must have a really cool dad","author":"@fignuuuts","author_id":"UC6JtSRDcxaUMfxvKbBz3hdQ","like_count":1,"published_time":"2 years ago"},{"id":"UgwWLrufjJ5sbLDCkxF4AaABAg","text":"just in case, the modulo implementation works out if you use integer division not \"normal\" division\n(2//5)*5=0, but (2/5)*5=2","author":"@maydude2","author_id":"UCminbZdDmzr4QsUH1B5Fwyg","like_count":6,"published_time":"2 years ago"},{"id":"UgxEwA0HYsWpnm94ol14AaABAg","text":"This is a great introduction and walk through for newcomers to assembly, but beware that the implementation has a quite significant flaw that will only reveal itself when called from other functions that have several live registers and happen to use r4 and store a value in it when it makes the call to this gcd function. The calling function will expect that the gcd function preserves the r4 register, as it is not a scratch register like r0-r3 are. This will manifest in miscalculations, unpredictable behavior and likely instability/crashes in the application using this function. An easy fix would be to push the r4 register along with lr to the stack, and pop it again (i.e. push {r4, lr} - pop {r4, pc}), but this of course increases the stack usage even more. Another approach would be to use r12 which is also a scratch register.\n\nIt would also be a good idea to make the implementation non-recursive as it can overflow the stack if it recurses too many times. For this algorithm this is quite easy as you can do tail call optimization by simply removing the push, replacing the pop by \"bx lr\" and doing a \"b gcd\" instead of \"bl gcd\" (which means the lr does not get overwritten for each iteration and retains the original return address that was written when the function was called the first time). This means the stack won't grow for each iteration.","author":"@ThomasThorsen","author_id":"UCrnn5DYsdOmhT13aXqqsUUg","like_count":97,"published_time":"2 years ago"},{"id":"UgxQn1SKh8yO_ciQy_54AaABAg","text":"weird way to propose but yes I accept","author":"@eduardoignacioroblessosa6349","author_id":"UCSDgxJoiZWswDOpph8sGn9w","like_count":2,"published_time":"2 years ago"},{"id":"UgxI0UdR8HAuTIewPzp4AaABAg","text":"looking for YouTuber making tutorial about arm assembly, never found, and tonight YouTube recommended this channel, okay YouTube, okay","author":"@hlodvic6678","author_id":"UCpvr8OL9OqXpkTIVp_y-Kxg","like_count":1,"published_time":"2 years ago"},{"id":"UgwEkRVspJzaseKBgLB4AaABAg","text":"Very nice walk-through! Small tip: if you ‘:set autoindent expandtab tabstop=8’, you can then use the <TAB> key to indent with spaces, and you will have a nicer vim experience.","author":"@edgarbonet1","author_id":"UC9KL7XU5j5HX-FbEJKJPtlg","like_count":1,"published_time":"11 months ago"},{"id":"UgwNKziAUmlG6AXRII14AaABAg","text":"praise the algorithm gods... how am i only just learning about this channel?","author":"@gcrannell","author_id":"UCpnZDR1AXRsYtMcDw35hQHw","like_count":48,"published_time":"2 years ago"},{"id":"UgzhDX6U_0ORODQO7fl4AaABAg","text":"Took me a while to realize the whispering at the start reminds me of 'AIR - How Does It Make You Feel? '\nHad to re play that at least 5 times, and then walked around for a bit, before I knew what it reminded me of.","author":"@josvromans","author_id":"UChxcImh6byUqOdZUrjpAjsA","like_count":0,"published_time":"2 years ago"},{"id":"UgxKy4C0T-wMsaqh_qp4AaABAg","text":"So it's been a few years since I was last writing in ARM asm (32-bit MCUs), so I might be a bit rusty... but I thought I saw a few tricks you'd missed, opened a notepad and downloaded an arm instruction-set reference and had a go myself. What I noticed:\n\n1: this is an ideal opportunity for tail recursion, simplifying the recursion to effectively a loop and removing the need to unwind the calls from the stack at the end\n2: move can set flags, removing the need to compare to determine zero both on entry and within the loop\n3: once you don't need to push/pop, bx lr can be used to return and can even be used with condition codes\n\n;; arm version\n\ngcd:\n\tmovs\tr1, r1\t\t;; mov can set flags? easiest way to get the z flag set for a zero input?\n\tbxeq\tlr\t\t\t;; conditional return. nice. assumes A32 instruction set tho...\n.loop:\n\tsdiv\t\tr2, r0, r1\t\t;; I find it surprising that ARM doesn't have some way to return\n\tmul\t\tr2, r2, r1\t\t;;  the remainder from a division... the bits are right there at the\n\tsub\t\tr2, r0, r2\t\t;;  end of the process, but then they get lost? and I have to recompute them? smh.\n\tmov\tr0, r1\t\t;; but even so, the ARM version is still smaller and neater than the x86,\n\tmovs\tr1, r2\t\t;;  which has to dance around the fixed register usage of its DIV instruction\n\tbne\t\tloop\t\t;; mov setting flags means that we can conditionally loop - also could set flags on the sub\n\tbx\t\tlr\t\t\t;; tail recursion means no push lr/pop pc, and we can use the direct return\n\n4: all this is very academic since most of the time will be in the div operation anyway...\n\n;; x86 version for comparison\n\ngcd:\t\t\t\t\t; expects a in edi, b in esi\n\tmov\teax, edi\n\ttest\t\tesi, esi\n\tjz\t\t.out\t\t\t;; no conditional return\n.loop:\n\txor\t\tedx, edx\t\t;; top half of dividand must be zeroed\n\tdiv\t\tesi\t\t\t;; div takes edx:eax as dividand, returns quotient in eax and remainder in edx\n\tmov\teax, esi\n\tmov\tesi, edx\n\ttest\t\tedx, edx\t\t;; have to use dedicated instruction for setting flags\n\tjnz\t\t.loop\t\t;; but at least these test/branch combo's get turned into a single µop when executed\n.out:\n\tret\t\t\t\t\t; return is in eax\n\n;;; the iterative logic as C\n\nint gcd(int a, int b) {\n\tif(!b) return a;\n\tint c;\n\twhile(c = a % b) { a = b; b = c; }\n\treturn b;\n}","author":"@treelibrarian7618","author_id":"UCFXKR8B0LqYQAGXNLWOuzBw","like_count":89,"published_time":"2 years ago"},{"id":"UgydkMM5TmT0NWFIDOJ4AaABAg","text":"I finally watch Lain and now the Youtube algorithm is rewarding me","author":"@Summanis","author_id":"UC9hG-mlN6ktivoTLV7snN9Q","like_count":84,"published_time":"2 years ago"},{"id":"UgwFY-PWCyogyUf_s6h4AaABAg","text":"I don't know, this just clicks every key, this atmosphere is perfect","author":"@cheleon94","author_id":"UCsj1bsS7_BkCqx57G48arnA","like_count":0,"published_time":"2 years ago"},{"id":"Ugw1I89X4X0aVw37Brp4AaABAg","text":"Everybody who comments \"the algorithm brought me here\" needs to immediately like and subscribe. Thats how we can boost channels like this","author":"@gcrannell","author_id":"UCpnZDR1AXRsYtMcDw35hQHw","like_count":1,"published_time":"2 years ago"},{"id":"UgyKnvK90V3kgVl-wpd4AaABAg","text":"I don't know what the heckin flip I'm watching but I freakin know it's epic dude.","author":"@jonasc1221","author_id":"UC0-NCPzaT7XjGFdXAT4uXrA","like_count":1,"published_time":"2 years ago"},{"id":"UgzUmGw6JCivvaTQ6Ml4AaABAg","text":"Underrated channel. I cannot wait to get fat enough in my CS courses to understand this","author":"@mebibyte9347","author_id":"UCdhqpME4X4_bQB9Esg7pCtw","like_count":89,"published_time":"2 years ago"},{"id":"Ugzv0nPUexcaoURHiRF4AaABAg","text":"Serial Experiments Lain! And the Wired. Wow!!! 😳 Awesome references. Just stumbled on this channel, so I wanted to acknowledge that. 😊","author":"@traal","author_id":"UC8kVxpH5j7I_613bRZ_d5ig","like_count":32,"published_time":"2 years ago"},{"id":"UgwmV2Hurx1shc1pZtR4AaABAg","text":"Just as a clarification: argument passing in asm is standardized. The requirements for the caller and callee are defined by the \"arm thumb procedure call standard\" (ATPCS). If you follow this standard you can also call c functions from asm code","author":"@TheGiuse45","author_id":"UCGazWqoK267ml6t3F0NZpqg","like_count":0,"published_time":"2 years ago"},{"id":"Ugz-7QdxrX4u307hjx14AaABAg","text":"I love the XP rice 😂","author":"@thejintent2770","author_id":"UCo_w3QOCgmvgW0bP6nyWlLw","like_count":10,"published_time":"2 years ago"},{"id":"UgyKSncBdPsNdD792dx4AaABAg","text":"As someone who subscribes to a ton of tech-related channels, this is the first time YouTube recommended me to this channel.","author":"@chyldstudios","author_id":"UCoxgRBEk_fIKnlg_Qx8ughQ","like_count":396,"published_time":"2 years ago"},{"id":"Ugyt6Z4xGrMspdGvyKx4AaABAg","text":"Easily the greatest common divisor in the history of all common divisors","author":"@maisylover","author_id":"UCO_UB8B3SZ2M0uPZ0gp9aKQ","like_count":252,"published_time":"2 years ago"},{"id":"Ugx2A2jKZ5xI6NegQyl4AaABAg","text":"I was looking for something to snooze to and thought this was ASMR Assembly.","author":"@maelstrom57","author_id":"UC9BJqAqRlOJBAA0O4WYSmnw","like_count":77,"published_time":"2 years ago"},{"id":"UgxEwA0HYsWpnm94ol14AaABAg","text":"This is a great introduction and walk through for newcomers to assembly, but beware that the implementation has a quite significant flaw that will only reveal itself when called from other functions that have several live registers and happen to use r4 and store a value in it when it makes the call to this gcd function. The calling function will expect that the gcd function preserves the r4 register, as it is not a scratch register like r0-r3 are. This will manifest in miscalculations, unpredictable behavior and likely instability/crashes in the application using this function. An easy fix would be to push the r4 register along with lr to the stack, and pop it again (i.e. push {r4, lr} - pop {r4, pc}), but this of course increases the stack usage even more. Another approach would be to use r12 which is also a scratch register.\n\nIt would also be a good idea to make the implementation non-recursive as it can overflow the stack if it recurses too many times. For this algorithm this is quite easy as you can do tail call optimization by simply removing the push, replacing the pop by \"bx lr\" and doing a \"b gcd\" instead of \"bl gcd\" (which means the lr does not get overwritten for each iteration and retains the original return address that was written when the function was called the first time). This means the stack won't grow for each iteration.","author":"@ThomasThorsen","author_id":"UCrnn5DYsdOmhT13aXqqsUUg","like_count":97,"published_time":"2 years ago"},{"id":"UgwNKziAUmlG6AXRII14AaABAg","text":"praise the algorithm gods... how am i only just learning about this channel?","author":"@gcrannell","author_id":"UCpnZDR1AXRsYtMcDw35hQHw","like_count":48,"published_time":"2 years ago"},{"id":"UgydkMM5TmT0NWFIDOJ4AaABAg","text":"I finally watch Lain and now the Youtube algorithm is rewarding me","author":"@Summanis","author_id":"UC9hG-mlN6ktivoTLV7snN9Q","like_count":84,"published_time":"2 years ago"},{"id":"Ugz-7QdxrX4u307hjx14AaABAg","text":"I love the XP rice 😂","author":"@thejintent2770","author_id":"UCo_w3QOCgmvgW0bP6nyWlLw","like_count":10,"published_time":"2 years ago"},{"id":"UgzUmGw6JCivvaTQ6Ml4AaABAg","text":"Underrated channel. I cannot wait to get fat enough in my CS courses to understand this","author":"@mebibyte9347","author_id":"UCdhqpME4X4_bQB9Esg7pCtw","like_count":89,"published_time":"2 years ago"},{"id":"UgzbfKnwxE7CD2fZxQ54AaABAg","text":"The quality of the video and the content is top notch. Here before 1 M subscribers","author":"@ogphoenix8965","author_id":"UCo6f35f9M3xqAoGKM5OGwfg","like_count":20,"published_time":"2 years ago"},{"id":"UgxKy4C0T-wMsaqh_qp4AaABAg","text":"So it's been a few years since I was last writing in ARM asm (32-bit MCUs), so I might be a bit rusty... but I thought I saw a few tricks you'd missed, opened a notepad and downloaded an arm instruction-set reference and had a go myself. What I noticed:\n\n1: this is an ideal opportunity for tail recursion, simplifying the recursion to effectively a loop and removing the need to unwind the calls from the stack at the end\n2: move can set flags, removing the need to compare to determine zero both on entry and within the loop\n3: once you don't need to push/pop, bx lr can be used to return and can even be used with condition codes\n\n;; arm version\n\ngcd:\n\tmovs\tr1, r1\t\t;; mov can set flags? easiest way to get the z flag set for a zero input?\n\tbxeq\tlr\t\t\t;; conditional return. nice. assumes A32 instruction set tho...\n.loop:\n\tsdiv\t\tr2, r0, r1\t\t;; I find it surprising that ARM doesn't have some way to return\n\tmul\t\tr2, r2, r1\t\t;;  the remainder from a division... the bits are right there at the\n\tsub\t\tr2, r0, r2\t\t;;  end of the process, but then they get lost? and I have to recompute them? smh.\n\tmov\tr0, r1\t\t;; but even so, the ARM version is still smaller and neater than the x86,\n\tmovs\tr1, r2\t\t;;  which has to dance around the fixed register usage of its DIV instruction\n\tbne\t\tloop\t\t;; mov setting flags means that we can conditionally loop - also could set flags on the sub\n\tbx\t\tlr\t\t\t;; tail recursion means no push lr/pop pc, and we can use the direct return\n\n4: all this is very academic since most of the time will be in the div operation anyway...\n\n;; x86 version for comparison\n\ngcd:\t\t\t\t\t; expects a in edi, b in esi\n\tmov\teax, edi\n\ttest\t\tesi, esi\n\tjz\t\t.out\t\t\t;; no conditional return\n.loop:\n\txor\t\tedx, edx\t\t;; top half of dividand must be zeroed\n\tdiv\t\tesi\t\t\t;; div takes edx:eax as dividand, returns quotient in eax and remainder in edx\n\tmov\teax, esi\n\tmov\tesi, edx\n\ttest\t\tedx, edx\t\t;; have to use dedicated instruction for setting flags\n\tjnz\t\t.loop\t\t;; but at least these test/branch combo's get turned into a single µop when executed\n.out:\n\tret\t\t\t\t\t; return is in eax\n\n;;; the iterative logic as C\n\nint gcd(int a, int b) {\n\tif(!b) return a;\n\tint c;\n\twhile(c = a % b) { a = b; b = c; }\n\treturn b;\n}","author":"@treelibrarian7618","author_id":"UCFXKR8B0LqYQAGXNLWOuzBw","like_count":89,"published_time":"2 years ago"},{"id":"UgyKnvK90V3kgVl-wpd4AaABAg","text":"I don't know what the heckin flip I'm watching but I freakin know it's epic dude.","author":"@jonasc1221","author_id":"UC0-NCPzaT7XjGFdXAT4uXrA","like_count":1,"published_time":"2 years ago"},{"id":"UgwWLrufjJ5sbLDCkxF4AaABAg","text":"just in case, the modulo implementation works out if you use integer division not \"normal\" division\n(2//5)*5=0, but (2/5)*5=2","author":"@maydude2","author_id":"UCminbZdDmzr4QsUH1B5Fwyg","like_count":6,"published_time":"2 years ago"},{"id":"UgwEkRVspJzaseKBgLB4AaABAg","text":"Very nice walk-through! Small tip: if you ‘:set autoindent expandtab tabstop=8’, you can then use the <TAB> key to indent with spaces, and you will have a nicer vim experience.","author":"@edgarbonet1","author_id":"UC9KL7XU5j5HX-FbEJKJPtlg","like_count":1,"published_time":"11 months ago"},{"id":"UgxI0UdR8HAuTIewPzp4AaABAg","text":"looking for YouTuber making tutorial about arm assembly, never found, and tonight YouTube recommended this channel, okay YouTube, okay","author":"@hlodvic6678","author_id":"UCpvr8OL9OqXpkTIVp_y-Kxg","like_count":1,"published_time":"2 years ago"},{"id":"Ugw1I89X4X0aVw37Brp4AaABAg","text":"Everybody who comments \"the algorithm brought me here\" needs to immediately like and subscribe. Thats how we can boost channels like this","author":"@gcrannell","author_id":"UCpnZDR1AXRsYtMcDw35hQHw","like_count":1,"published_time":"2 years ago"},{"id":"UgyQ5xOf7YTmJLDvagR4AaABAg","text":"I have been watching tech and programming channels for many years. This is the first time YouTube has recommended you. Glad to see it!","author":"@PaulEmsley","author_id":"UCbHAnhn_6MOmmjMMhR_0qkQ","like_count":10,"published_time":"2 years ago"},{"id":"UgxQn1SKh8yO_ciQy_54AaABAg","text":"weird way to propose but yes I accept","author":"@eduardoignacioroblessosa6349","author_id":"UCSDgxJoiZWswDOpph8sGn9w","like_count":2,"published_time":"2 years ago"},{"id":"UgyDOiM-YIy5EaE6ouZ4AaABAg","text":"OMG. Last time I wrote assembly was like 20 years ago! I love this woman!","author":"@sushiConPorotos","author_id":"UC1V0DFx7BlfCI9xVKPgQsOA","like_count":10,"published_time":"2 years ago"},{"id":"UgyHWJWuOK-uTLDe3yF4AaABAg","text":"I last coded in Arm for an Acorn Archimedes about 35 years ago. Thanks for the memory jolt.","author":"@CrestRising","author_id":"UCWbsTFBqosZXS2J_P-j4XCQ","like_count":1,"published_time":"2 years ago"},{"id":"Ugzv0nPUexcaoURHiRF4AaABAg","text":"Serial Experiments Lain! And the Wired. Wow!!! 😳 Awesome references. Just stumbled on this channel, so I wanted to acknowledge that. 😊","author":"@traal","author_id":"UC8kVxpH5j7I_613bRZ_d5ig","like_count":32,"published_time":"2 years ago"},{"id":"UgyKSncBdPsNdD792dx4AaABAg","text":"As someone who subscribes to a ton of tech-related channels, this is the first time YouTube recommended me to this channel.","author":"@chyldstudios","author_id":"UCoxgRBEk_fIKnlg_Qx8ughQ","like_count":396,"published_time":"2 years ago"},{"id":"Ugyt6Z4xGrMspdGvyKx4AaABAg","text":"Easily the greatest common divisor in the history of all common divisors","author":"@maisylover","author_id":"UCO_UB8B3SZ2M0uPZ0gp9aKQ","like_count":252,"published_time":"2 years ago"},{"id":"Ugx2A2jKZ5xI6NegQyl4AaABAg","text":"I was looking for something to snooze to and thought this was ASMR Assembly.","author":"@maelstrom57","author_id":"UC9BJqAqRlOJBAA0O4WYSmnw","like_count":77,"published_time":"2 years ago"},{"id":"UgxEwA0HYsWpnm94ol14AaABAg","text":"This is a great introduction and walk through for newcomers to assembly, but beware that the implementation has a quite significant flaw that will only reveal itself when called from other functions that have several live registers and happen to use r4 and store a value in it when it makes the call to this gcd function. The calling function will expect that the gcd function preserves the r4 register, as it is not a scratch register like r0-r3 are. This will manifest in miscalculations, unpredictable behavior and likely instability/crashes in the application using this function. An easy fix would be to push the r4 register along with lr to the stack, and pop it again (i.e. push {r4, lr} - pop {r4, pc}), but this of course increases the stack usage even more. Another approach would be to use r12 which is also a scratch register.\n\nIt would also be a good idea to make the implementation non-recursive as it can overflow the stack if it recurses too many times. For this algorithm this is quite easy as you can do tail call optimization by simply removing the push, replacing the pop by \"bx lr\" and doing a \"b gcd\" instead of \"bl gcd\" (which means the lr does not get overwritten for each iteration and retains the original return address that was written when the function was called the first time). This means the stack won't grow for each iteration.","author":"@ThomasThorsen","author_id":"UCrnn5DYsdOmhT13aXqqsUUg","like_count":97,"published_time":"2 years ago"},{"id":"UgwNKziAUmlG6AXRII14AaABAg","text":"praise the algorithm gods... how am i only just learning about this channel?","author":"@gcrannell","author_id":"UCpnZDR1AXRsYtMcDw35hQHw","like_count":48,"published_time":"2 years ago"},{"id":"UgydkMM5TmT0NWFIDOJ4AaABAg","text":"I finally watch Lain and now the Youtube algorithm is rewarding me","author":"@Summanis","author_id":"UC9hG-mlN6ktivoTLV7snN9Q","like_count":84,"published_time":"2 years ago"},{"id":"Ugz-7QdxrX4u307hjx14AaABAg","text":"I love the XP rice 😂","author":"@thejintent2770","author_id":"UCo_w3QOCgmvgW0bP6nyWlLw","like_count":10,"published_time":"2 years ago"},{"id":"UgzUmGw6JCivvaTQ6Ml4AaABAg","text":"Underrated channel. I cannot wait to get fat enough in my CS courses to understand this","author":"@mebibyte9347","author_id":"UCdhqpME4X4_bQB9Esg7pCtw","like_count":89,"published_time":"2 years ago"},{"id":"UgzbfKnwxE7CD2fZxQ54AaABAg","text":"The quality of the video and the content is top notch. Here before 1 M subscribers","author":"@ogphoenix8965","author_id":"UCo6f35f9M3xqAoGKM5OGwfg","like_count":20,"published_time":"2 years ago"},{"id":"UgxKy4C0T-wMsaqh_qp4AaABAg","text":"So it's been a few years since I was last writing in ARM asm (32-bit MCUs), so I might be a bit rusty... but I thought I saw a few tricks you'd missed, opened a notepad and downloaded an arm instruction-set reference and had a go myself. What I noticed:\n\n1: this is an ideal opportunity for tail recursion, simplifying the recursion to effectively a loop and removing the need to unwind the calls from the stack at the end\n2: move can set flags, removing the need to compare to determine zero both on entry and within the loop\n3: once you don't need to push/pop, bx lr can be used to return and can even be used with condition codes\n\n;; arm version\n\ngcd:\n\tmovs\tr1, r1\t\t;; mov can set flags? easiest way to get the z flag set for a zero input?\n\tbxeq\tlr\t\t\t;; conditional return. nice. assumes A32 instruction set tho...\n.loop:\n\tsdiv\t\tr2, r0, r1\t\t;; I find it surprising that ARM doesn't have some way to return\n\tmul\t\tr2, r2, r1\t\t;;  the remainder from a division... the bits are right there at the\n\tsub\t\tr2, r0, r2\t\t;;  end of the process, but then they get lost? and I have to recompute them? smh.\n\tmov\tr0, r1\t\t;; but even so, the ARM version is still smaller and neater than the x86,\n\tmovs\tr1, r2\t\t;;  which has to dance around the fixed register usage of its DIV instruction\n\tbne\t\tloop\t\t;; mov setting flags means that we can conditionally loop - also could set flags on the sub\n\tbx\t\tlr\t\t\t;; tail recursion means no push lr/pop pc, and we can use the direct return\n\n4: all this is very academic since most of the time will be in the div operation anyway...\n\n;; x86 version for comparison\n\ngcd:\t\t\t\t\t; expects a in edi, b in esi\n\tmov\teax, edi\n\ttest\t\tesi, esi\n\tjz\t\t.out\t\t\t;; no conditional return\n.loop:\n\txor\t\tedx, edx\t\t;; top half of dividand must be zeroed\n\tdiv\t\tesi\t\t\t;; div takes edx:eax as dividand, returns quotient in eax and remainder in edx\n\tmov\teax, esi\n\tmov\tesi, edx\n\ttest\t\tedx, edx\t\t;; have to use dedicated instruction for setting flags\n\tjnz\t\t.loop\t\t;; but at least these test/branch combo's get turned into a single µop when executed\n.out:\n\tret\t\t\t\t\t; return is in eax\n\n;;; the iterative logic as C\n\nint gcd(int a, int b) {\n\tif(!b) return a;\n\tint c;\n\twhile(c = a % b) { a = b; b = c; }\n\treturn b;\n}","author":"@treelibrarian7618","author_id":"UCFXKR8B0LqYQAGXNLWOuzBw","like_count":89,"published_time":"2 years ago"},{"id":"UgyKnvK90V3kgVl-wpd4AaABAg","text":"I don't know what the heckin flip I'm watching but I freakin know it's epic dude.","author":"@jonasc1221","author_id":"UC0-NCPzaT7XjGFdXAT4uXrA","like_count":1,"published_time":"2 years ago"},{"id":"UgwWLrufjJ5sbLDCkxF4AaABAg","text":"just in case, the modulo implementation works out if you use integer division not \"normal\" division\n(2//5)*5=0, but (2/5)*5=2","author":"@maydude2","author_id":"UCminbZdDmzr4QsUH1B5Fwyg","like_count":6,"published_time":"2 years ago"},{"id":"UgwEkRVspJzaseKBgLB4AaABAg","text":"Very nice walk-through! Small tip: if you ‘:set autoindent expandtab tabstop=8’, you can then use the <TAB> key to indent with spaces, and you will have a nicer vim experience.","author":"@edgarbonet1","author_id":"UC9KL7XU5j5HX-FbEJKJPtlg","like_count":1,"published_time":"11 months ago"},{"id":"UgxI0UdR8HAuTIewPzp4AaABAg","text":"looking for YouTuber making tutorial about arm assembly, never found, and tonight YouTube recommended this channel, okay YouTube, okay","author":"@hlodvic6678","author_id":"UCpvr8OL9OqXpkTIVp_y-Kxg","like_count":1,"published_time":"2 years ago"},{"id":"Ugw1I89X4X0aVw37Brp4AaABAg","text":"Everybody who comments \"the algorithm brought me here\" needs to immediately like and subscribe. Thats how we can boost channels like this","author":"@gcrannell","author_id":"UCpnZDR1AXRsYtMcDw35hQHw","like_count":1,"published_time":"2 years ago"},{"id":"UgyQ5xOf7YTmJLDvagR4AaABAg","text":"I have been watching tech and programming channels for many years. This is the first time YouTube has recommended you. Glad to see it!","author":"@PaulEmsley","author_id":"UCbHAnhn_6MOmmjMMhR_0qkQ","like_count":10,"published_time":"2 years ago"},{"id":"UgxQn1SKh8yO_ciQy_54AaABAg","text":"weird way to propose but yes I accept","author":"@eduardoignacioroblessosa6349","author_id":"UCSDgxJoiZWswDOpph8sGn9w","like_count":2,"published_time":"2 years ago"},{"id":"UgyDOiM-YIy5EaE6ouZ4AaABAg","text":"OMG. Last time I wrote assembly was like 20 years ago! I love this woman!","author":"@sushiConPorotos","author_id":"UC1V0DFx7BlfCI9xVKPgQsOA","like_count":10,"published_time":"2 years ago"},{"id":"UgyHWJWuOK-uTLDe3yF4AaABAg","text":"I last coded in Arm for an Acorn Archimedes about 35 years ago. Thanks for the memory jolt.","author":"@CrestRising","author_id":"UCWbsTFBqosZXS2J_P-j4XCQ","like_count":1,"published_time":"2 years ago"},{"id":"Ugzv0nPUexcaoURHiRF4AaABAg","text":"Serial Experiments Lain! And the Wired. Wow!!! 😳 Awesome references. Just stumbled on this channel, so I wanted to acknowledge that. 😊","author":"@traal","author_id":"UC8kVxpH5j7I_613bRZ_d5ig","like_count":32,"published_time":"2 years ago"},{"id":"UgyKSncBdPsNdD792dx4AaABAg","text":"As someone who subscribes to a ton of tech-related channels, this is the first time YouTube recommended me to this channel.","author":"@chyldstudios","author_id":"UCoxgRBEk_fIKnlg_Qx8ughQ","like_count":396,"published_time":"2 years ago"},{"id":"Ugyt6Z4xGrMspdGvyKx4AaABAg","text":"Easily the greatest common divisor in the history of all common divisors","author":"@maisylover","author_id":"UCO_UB8B3SZ2M0uPZ0gp9aKQ","like_count":252,"published_time":"2 years ago"},{"id":"Ugx2A2jKZ5xI6NegQyl4AaABAg","text":"I was looking for something to snooze to and thought this was ASMR Assembly.","author":"@maelstrom57","author_id":"UC9BJqAqRlOJBAA0O4WYSmnw","like_count":77,"published_time":"2 years ago"},{"id":"UgxEwA0HYsWpnm94ol14AaABAg","text":"This is a great introduction and walk through for newcomers to assembly, but beware that the implementation has a quite significant flaw that will only reveal itself when called from other functions that have several live registers and happen to use r4 and store a value in it when it makes the call to this gcd function. The calling function will expect that the gcd function preserves the r4 register, as it is not a scratch register like r0-r3 are. This will manifest in miscalculations, unpredictable behavior and likely instability/crashes in the application using this function. An easy fix would be to push the r4 register along with lr to the stack, and pop it again (i.e. push {r4, lr} - pop {r4, pc}), but this of course increases the stack usage even more. Another approach would be to use r12 which is also a scratch register.\n\nIt would also be a good idea to make the implementation non-recursive as it can overflow the stack if it recurses too many times. For this algorithm this is quite easy as you can do tail call optimization by simply removing the push, replacing the pop by \"bx lr\" and doing a \"b gcd\" instead of \"bl gcd\" (which means the lr does not get overwritten for each iteration and retains the original return address that was written when the function was called the first time). This means the stack won't grow for each iteration.","author":"@ThomasThorsen","author_id":"UCrnn5DYsdOmhT13aXqqsUUg","like_count":97,"published_time":"2 years ago"},{"id":"UgwWLrufjJ5sbLDCkxF4AaABAg","text":"just in case, the modulo implementation works out if you use integer division not \"normal\" division\n(2//5)*5=0, but (2/5)*5=2","author":"@maydude2","author_id":"UCminbZdDmzr4QsUH1B5Fwyg","like_count":6,"published_time":"2 years ago"},{"id":"UgwNKziAUmlG6AXRII14AaABAg","text":"praise the algorithm gods... how am i only just learning about this channel?","author":"@gcrannell","author_id":"UCpnZDR1AXRsYtMcDw35hQHw","like_count":48,"published_time":"2 years ago"},{"id":"UgydkMM5TmT0NWFIDOJ4AaABAg","text":"I finally watch Lain and now the Youtube algorithm is rewarding me","author":"@Summanis","author_id":"UC9hG-mlN6ktivoTLV7snN9Q","like_count":84,"published_time":"2 years ago"},{"id":"UgyQ5xOf7YTmJLDvagR4AaABAg","text":"I have been watching tech and programming channels for many years. This is the first time YouTube has recommended you. Glad to see it!","author":"@PaulEmsley","author_id":"UCbHAnhn_6MOmmjMMhR_0qkQ","like_count":10,"published_time":"2 years ago"},{"id":"UgzbfKnwxE7CD2fZxQ54AaABAg","text":"The quality of the video and the content is top notch. Here before 1 M subscribers","author":"@ogphoenix8965","author_id":"UCo6f35f9M3xqAoGKM5OGwfg","like_count":20,"published_time":"2 years ago"},{"id":"Ugyfje5VGCaYkZjTujR4AaABAg","text":"I feel like Laurie must have a really cool dad","author":"@fignuuuts","author_id":"UC6JtSRDcxaUMfxvKbBz3hdQ","like_count":1,"published_time":"2 years ago"},{"id":"Ugz-7QdxrX4u307hjx14AaABAg","text":"I love the XP rice 😂","author":"@thejintent2770","author_id":"UCo_w3QOCgmvgW0bP6nyWlLw","like_count":10,"published_time":"2 years ago"},{"id":"UgzUmGw6JCivvaTQ6Ml4AaABAg","text":"Underrated channel. I cannot wait to get fat enough in my CS courses to understand this","author":"@mebibyte9347","author_id":"UCdhqpME4X4_bQB9Esg7pCtw","like_count":89,"published_time":"2 years ago"},{"id":"UgxKy4C0T-wMsaqh_qp4AaABAg","text":"So it's been a few years since I was last writing in ARM asm (32-bit MCUs), so I might be a bit rusty... but I thought I saw a few tricks you'd missed, opened a notepad and downloaded an arm instruction-set reference and had a go myself. What I noticed:\n\n1: this is an ideal opportunity for tail recursion, simplifying the recursion to effectively a loop and removing the need to unwind the calls from the stack at the end\n2: move can set flags, removing the need to compare to determine zero both on entry and within the loop\n3: once you don't need to push/pop, bx lr can be used to return and can even be used with condition codes\n\n;; arm version\n\ngcd:\n\tmovs\tr1, r1\t\t;; mov can set flags? easiest way to get the z flag set for a zero input?\n\tbxeq\tlr\t\t\t;; conditional return. nice. assumes A32 instruction set tho...\n.loop:\n\tsdiv\t\tr2, r0, r1\t\t;; I find it surprising that ARM doesn't have some way to return\n\tmul\t\tr2, r2, r1\t\t;;  the remainder from a division... the bits are right there at the\n\tsub\t\tr2, r0, r2\t\t;;  end of the process, but then they get lost? and I have to recompute them? smh.\n\tmov\tr0, r1\t\t;; but even so, the ARM version is still smaller and neater than the x86,\n\tmovs\tr1, r2\t\t;;  which has to dance around the fixed register usage of its DIV instruction\n\tbne\t\tloop\t\t;; mov setting flags means that we can conditionally loop - also could set flags on the sub\n\tbx\t\tlr\t\t\t;; tail recursion means no push lr/pop pc, and we can use the direct return\n\n4: all this is very academic since most of the time will be in the div operation anyway...\n\n;; x86 version for comparison\n\ngcd:\t\t\t\t\t; expects a in edi, b in esi\n\tmov\teax, edi\n\ttest\t\tesi, esi\n\tjz\t\t.out\t\t\t;; no conditional return\n.loop:\n\txor\t\tedx, edx\t\t;; top half of dividand must be zeroed\n\tdiv\t\tesi\t\t\t;; div takes edx:eax as dividand, returns quotient in eax and remainder in edx\n\tmov\teax, esi\n\tmov\tesi, edx\n\ttest\t\tedx, edx\t\t;; have to use dedicated instruction for setting flags\n\tjnz\t\t.loop\t\t;; but at least these test/branch combo's get turned into a single µop when executed\n.out:\n\tret\t\t\t\t\t; return is in eax\n\n;;; the iterative logic as C\n\nint gcd(int a, int b) {\n\tif(!b) return a;\n\tint c;\n\twhile(c = a % b) { a = b; b = c; }\n\treturn b;\n}","author":"@treelibrarian7618","author_id":"UCFXKR8B0LqYQAGXNLWOuzBw","like_count":89,"published_time":"2 years ago"},{"id":"Ugzv0nPUexcaoURHiRF4AaABAg","text":"Serial Experiments Lain! And the Wired. Wow!!! 😳 Awesome references. Just stumbled on this channel, so I wanted to acknowledge that. 😊","author":"@traal","author_id":"UC8kVxpH5j7I_613bRZ_d5ig","like_count":32,"published_time":"2 years ago"},{"id":"UgxI0UdR8HAuTIewPzp4AaABAg","text":"looking for YouTuber making tutorial about arm assembly, never found, and tonight YouTube recommended this channel, okay YouTube, okay","author":"@hlodvic6678","author_id":"UCpvr8OL9OqXpkTIVp_y-Kxg","like_count":1,"published_time":"2 years ago"},{"id":"UgxHUVcRFzn00-r-oGd4AaABAg","text":"wtf, awesome! why haven't I discovered your channel sooner?","author":"@actualBIAS","author_id":"UCORcRkgJreedXIBryq7dJ8g","like_count":6,"published_time":"2 years ago"},{"id":"UgwEkRVspJzaseKBgLB4AaABAg","text":"Very nice walk-through! Small tip: if you ‘:set autoindent expandtab tabstop=8’, you can then use the <TAB> key to indent with spaces, and you will have a nicer vim experience.","author":"@edgarbonet1","author_id":"UC9KL7XU5j5HX-FbEJKJPtlg","like_count":1,"published_time":"11 months ago"},{"id":"UgynPYhdMW-qksKKtGx4AaABAg","text":"I'm instantly a fan! Notepad++, Windows XP, talking about assembly language, and why it's great to scaffold in higher-level languages is awesome. I'm looking forward to exploring more of your channel in the future! Thank you for this","author":"@rogerwinright2290","author_id":"UCL5UuslBh717oJVUoQXmEuQ","like_count":85,"published_time":"2 years ago"},{"id":"UgyKnvK90V3kgVl-wpd4AaABAg","text":"I don't know what the heckin flip I'm watching but I freakin know it's epic dude.","author":"@jonasc1221","author_id":"UC0-NCPzaT7XjGFdXAT4uXrA","like_count":1,"published_time":"2 years ago"},{"id":"UgyHWJWuOK-uTLDe3yF4AaABAg","text":"I last coded in Arm for an Acorn Archimedes about 35 years ago. Thanks for the memory jolt.","author":"@CrestRising","author_id":"UCWbsTFBqosZXS2J_P-j4XCQ","like_count":1,"published_time":"2 years ago"},{"id":"UgyKSncBdPsNdD792dx4AaABAg","text":"As someone who subscribes to a ton of tech-related channels, this is the first time YouTube recommended me to this channel.","author":"@chyldstudios","author_id":"UCoxgRBEk_fIKnlg_Qx8ughQ","like_count":396,"published_time":"2 years ago"},{"id":"Ugyt6Z4xGrMspdGvyKx4AaABAg","text":"Easily the greatest common divisor in the history of all common divisors","author":"@maisylover","author_id":"UCO_UB8B3SZ2M0uPZ0gp9aKQ","like_count":252,"published_time":"2 years ago"},{"id":"Ugx2A2jKZ5xI6NegQyl4AaABAg","text":"I was looking for something to snooze to and thought this was ASMR Assembly.","author":"@maelstrom57","author_id":"UC9BJqAqRlOJBAA0O4WYSmnw","like_count":77,"published_time":"2 years ago"},{"id":"UgxEwA0HYsWpnm94ol14AaABAg","text":"This is a great introduction and walk through for newcomers to assembly, but beware that the implementation has a quite significant flaw that will only reveal itself when called from other functions that have several live registers and happen to use r4 and store a value in it when it makes the call to this gcd function. The calling function will expect that the gcd function preserves the r4 register, as it is not a scratch register like r0-r3 are. This will manifest in miscalculations, unpredictable behavior and likely instability/crashes in the application using this function. An easy fix would be to push the r4 register along with lr to the stack, and pop it again (i.e. push {r4, lr} - pop {r4, pc}), but this of course increases the stack usage even more. Another approach would be to use r12 which is also a scratch register.\n\nIt would also be a good idea to make the implementation non-recursive as it can overflow the stack if it recurses too many times. For this algorithm this is quite easy as you can do tail call optimization by simply removing the push, replacing the pop by \"bx lr\" and doing a \"b gcd\" instead of \"bl gcd\" (which means the lr does not get overwritten for each iteration and retains the original return address that was written when the function was called the first time). This means the stack won't grow for each iteration.","author":"@ThomasThorsen","author_id":"UCrnn5DYsdOmhT13aXqqsUUg","like_count":97,"published_time":"2 years ago"},{"id":"UgwNKziAUmlG6AXRII14AaABAg","text":"praise the algorithm gods... how am i only just learning about this channel?","author":"@gcrannell","author_id":"UCpnZDR1AXRsYtMcDw35hQHw","like_count":48,"published_time":"2 years ago"},{"id":"UgydkMM5TmT0NWFIDOJ4AaABAg","text":"I finally watch Lain and now the Youtube algorithm is rewarding me","author":"@Summanis","author_id":"UC9hG-mlN6ktivoTLV7snN9Q","like_count":84,"published_time":"2 years ago"},{"id":"Ugz-7QdxrX4u307hjx14AaABAg","text":"I love the XP rice 😂","author":"@thejintent2770","author_id":"UCo_w3QOCgmvgW0bP6nyWlLw","like_count":10,"published_time":"2 years ago"},{"id":"UgzUmGw6JCivvaTQ6Ml4AaABAg","text":"Underrated channel. I cannot wait to get fat enough in my CS courses to understand this","author":"@mebibyte9347","author_id":"UCdhqpME4X4_bQB9Esg7pCtw","like_count":89,"published_time":"2 years ago"},{"id":"UgzbfKnwxE7CD2fZxQ54AaABAg","text":"The quality of the video and the content is top notch. Here before 1 M subscribers","author":"@ogphoenix8965","author_id":"UCo6f35f9M3xqAoGKM5OGwfg","like_count":20,"published_time":"2 years ago"},{"id":"UgxKy4C0T-wMsaqh_qp4AaABAg","text":"So it's been a few years since I was last writing in ARM asm (32-bit MCUs), so I might be a bit rusty... but I thought I saw a few tricks you'd missed, opened a notepad and downloaded an arm instruction-set reference and had a go myself. What I noticed:\n\n1: this is an ideal opportunity for tail recursion, simplifying the recursion to effectively a loop and removing the need to unwind the calls from the stack at the end\n2: move can set flags, removing the need to compare to determine zero both on entry and within the loop\n3: once you don't need to push/pop, bx lr can be used to return and can even be used with condition codes\n\n;; arm version\n\ngcd:\n\tmovs\tr1, r1\t\t;; mov can set flags? easiest way to get the z flag set for a zero input?\n\tbxeq\tlr\t\t\t;; conditional return. nice. assumes A32 instruction set tho...\n.loop:\n\tsdiv\t\tr2, r0, r1\t\t;; I find it surprising that ARM doesn't have some way to return\n\tmul\t\tr2, r2, r1\t\t;;  the remainder from a division... the bits are right there at the\n\tsub\t\tr2, r0, r2\t\t;;  end of the process, but then they get lost? and I have to recompute them? smh.\n\tmov\tr0, r1\t\t;; but even so, the ARM version is still smaller and neater than the x86,\n\tmovs\tr1, r2\t\t;;  which has to dance around the fixed register usage of its DIV instruction\n\tbne\t\tloop\t\t;; mov setting flags means that we can conditionally loop - also could set flags on the sub\n\tbx\t\tlr\t\t\t;; tail recursion means no push lr/pop pc, and we can use the direct return\n\n4: all this is very academic since most of the time will be in the div operation anyway...\n\n;; x86 version for comparison\n\ngcd:\t\t\t\t\t; expects a in edi, b in esi\n\tmov\teax, edi\n\ttest\t\tesi, esi\n\tjz\t\t.out\t\t\t;; no conditional return\n.loop:\n\txor\t\tedx, edx\t\t;; top half of dividand must be zeroed\n\tdiv\t\tesi\t\t\t;; div takes edx:eax as dividand, returns quotient in eax and remainder in edx\n\tmov\teax, esi\n\tmov\tesi, edx\n\ttest\t\tedx, edx\t\t;; have to use dedicated instruction for setting flags\n\tjnz\t\t.loop\t\t;; but at least these test/branch combo's get turned into a single µop when executed\n.out:\n\tret\t\t\t\t\t; return is in eax\n\n;;; the iterative logic as C\n\nint gcd(int a, int b) {\n\tif(!b) return a;\n\tint c;\n\twhile(c = a % b) { a = b; b = c; }\n\treturn b;\n}","author":"@treelibrarian7618","author_id":"UCFXKR8B0LqYQAGXNLWOuzBw","like_count":89,"published_time":"2 years ago"},{"id":"UgyKnvK90V3kgVl-wpd4AaABAg","text":"I don't know what the heckin flip I'm watching but I freakin know it's epic dude.","author":"@jonasc1221","author_id":"UC0-NCPzaT7XjGFdXAT4uXrA","like_count":1,"published_time":"2 years ago"},{"id":"UgwWLrufjJ5sbLDCkxF4AaABAg","text":"just in case, the modulo implementation works out if you use integer division not \"normal\" division\n(2//5)*5=0, but (2/5)*5=2","author":"@maydude2","author_id":"UCminbZdDmzr4QsUH1B5Fwyg","like_count":6,"published_time":"2 years ago"},{"id":"UgwEkRVspJzaseKBgLB4AaABAg","text":"Very nice walk-through! Small tip: if you ‘:set autoindent expandtab tabstop=8’, you can then use the <TAB> key to indent with spaces, and you will have a nicer vim experience.","author":"@edgarbonet1","author_id":"UC9KL7XU5j5HX-FbEJKJPtlg","like_count":1,"published_time":"11 months ago"},{"id":"UgxI0UdR8HAuTIewPzp4AaABAg","text":"looking for YouTuber making tutorial about arm assembly, never found, and tonight YouTube recommended this channel, okay YouTube, okay","author":"@hlodvic6678","author_id":"UCpvr8OL9OqXpkTIVp_y-Kxg","like_count":1,"published_time":"2 years ago"},{"id":"Ugw1I89X4X0aVw37Brp4AaABAg","text":"Everybody who comments \"the algorithm brought me here\" needs to immediately like and subscribe. Thats how we can boost channels like this","author":"@gcrannell","author_id":"UCpnZDR1AXRsYtMcDw35hQHw","like_count":1,"published_time":"2 years ago"},{"id":"UgyQ5xOf7YTmJLDvagR4AaABAg","text":"I have been watching tech and programming channels for many years. This is the first time YouTube has recommended you. Glad to see it!","author":"@PaulEmsley","author_id":"UCbHAnhn_6MOmmjMMhR_0qkQ","like_count":10,"published_time":"2 years ago"},{"id":"UgxQn1SKh8yO_ciQy_54AaABAg","text":"weird way to propose but yes I accept","author":"@eduardoignacioroblessosa6349","author_id":"UCSDgxJoiZWswDOpph8sGn9w","like_count":2,"published_time":"2 years ago"},{"id":"UgyDOiM-YIy5EaE6ouZ4AaABAg","text":"OMG. Last time I wrote assembly was like 20 years ago! I love this woman!","author":"@sushiConPorotos","author_id":"UC1V0DFx7BlfCI9xVKPgQsOA","like_count":10,"published_time":"2 years ago"},{"id":"UgyHWJWuOK-uTLDe3yF4AaABAg","text":"I last coded in Arm for an Acorn Archimedes about 35 years ago. Thanks for the memory jolt.","author":"@CrestRising","author_id":"UCWbsTFBqosZXS2J_P-j4XCQ","like_count":1,"published_time":"2 years ago"},{"id":"Ugzv0nPUexcaoURHiRF4AaABAg","text":"Serial Experiments Lain! And the Wired. Wow!!! 😳 Awesome references. Just stumbled on this channel, so I wanted to acknowledge that. 😊","author":"@traal","author_id":"UC8kVxpH5j7I_613bRZ_d5ig","like_count":32,"published_time":"2 years ago"},{"id":"UgyKSncBdPsNdD792dx4AaABAg","text":"As someone who subscribes to a ton of tech-related channels, this is the first time YouTube recommended me to this channel.","author":"@chyldstudios","author_id":"UCoxgRBEk_fIKnlg_Qx8ughQ","like_count":396,"published_time":"2 years ago"},{"id":"Ugyt6Z4xGrMspdGvyKx4AaABAg","text":"Easily the greatest common divisor in the history of all common divisors","author":"@maisylover","author_id":"UCO_UB8B3SZ2M0uPZ0gp9aKQ","like_count":252,"published_time":"2 years ago"},{"id":"Ugx2A2jKZ5xI6NegQyl4AaABAg","text":"I was looking for something to snooze to and thought this was ASMR Assembly.","author":"@maelstrom57","author_id":"UC9BJqAqRlOJBAA0O4WYSmnw","like_count":77,"published_time":"2 years ago"},{"id":"UgxEwA0HYsWpnm94ol14AaABAg","text":"This is a great introduction and walk through for newcomers to assembly, but beware that the implementation has a quite significant flaw that will only reveal itself when called from other functions that have several live registers and happen to use r4 and store a value in it when it makes the call to this gcd function. The calling function will expect that the gcd function preserves the r4 register, as it is not a scratch register like r0-r3 are. This will manifest in miscalculations, unpredictable behavior and likely instability/crashes in the application using this function. An easy fix would be to push the r4 register along with lr to the stack, and pop it again (i.e. push {r4, lr} - pop {r4, pc}), but this of course increases the stack usage even more. Another approach would be to use r12 which is also a scratch register.\n\nIt would also be a good idea to make the implementation non-recursive as it can overflow the stack if it recurses too many times. For this algorithm this is quite easy as you can do tail call optimization by simply removing the push, replacing the pop by \"bx lr\" and doing a \"b gcd\" instead of \"bl gcd\" (which means the lr does not get overwritten for each iteration and retains the original return address that was written when the function was called the first time). This means the stack won't grow for each iteration.","author":"@ThomasThorsen","author_id":"UCrnn5DYsdOmhT13aXqqsUUg","like_count":97,"published_time":"2 years ago"},{"id":"UgwNKziAUmlG6AXRII14AaABAg","text":"praise the algorithm gods... how am i only just learning about this channel?","author":"@gcrannell","author_id":"UCpnZDR1AXRsYtMcDw35hQHw","like_count":48,"published_time":"2 years ago"},{"id":"UgydkMM5TmT0NWFIDOJ4AaABAg","text":"I finally watch Lain and now the Youtube algorithm is rewarding me","author":"@Summanis","author_id":"UC9hG-mlN6ktivoTLV7snN9Q","like_count":84,"published_time":"2 years ago"},{"id":"Ugz-7QdxrX4u307hjx14AaABAg","text":"I love the XP rice 😂","author":"@thejintent2770","author_id":"UCo_w3QOCgmvgW0bP6nyWlLw","like_count":10,"published_time":"2 years ago"},{"id":"UgzUmGw6JCivvaTQ6Ml4AaABAg","text":"Underrated channel. I cannot wait to get fat enough in my CS courses to understand this","author":"@mebibyte9347","author_id":"UCdhqpME4X4_bQB9Esg7pCtw","like_count":89,"published_time":"2 years ago"},{"id":"UgzbfKnwxE7CD2fZxQ54AaABAg","text":"The quality of the video and the content is top notch. Here before 1 M subscribers","author":"@ogphoenix8965","author_id":"UCo6f35f9M3xqAoGKM5OGwfg","like_count":20,"published_time":"2 years ago"},{"id":"UgxKy4C0T-wMsaqh_qp4AaABAg","text":"So it's been a few years since I was last writing in ARM asm (32-bit MCUs), so I might be a bit rusty... but I thought I saw a few tricks you'd missed, opened a notepad and downloaded an arm instruction-set reference and had a go myself. What I noticed:\n\n1: this is an ideal opportunity for tail recursion, simplifying the recursion to effectively a loop and removing the need to unwind the calls from the stack at the end\n2: move can set flags, removing the need to compare to determine zero both on entry and within the loop\n3: once you don't need to push/pop, bx lr can be used to return and can even be used with condition codes\n\n;; arm version\n\ngcd:\n\tmovs\tr1, r1\t\t;; mov can set flags? easiest way to get the z flag set for a zero input?\n\tbxeq\tlr\t\t\t;; conditional return. nice. assumes A32 instruction set tho...\n.loop:\n\tsdiv\t\tr2, r0, r1\t\t;; I find it surprising that ARM doesn't have some way to return\n\tmul\t\tr2, r2, r1\t\t;;  the remainder from a division... the bits are right there at the\n\tsub\t\tr2, r0, r2\t\t;;  end of the process, but then they get lost? and I have to recompute them? smh.\n\tmov\tr0, r1\t\t;; but even so, the ARM version is still smaller and neater than the x86,\n\tmovs\tr1, r2\t\t;;  which has to dance around the fixed register usage of its DIV instruction\n\tbne\t\tloop\t\t;; mov setting flags means that we can conditionally loop - also could set flags on the sub\n\tbx\t\tlr\t\t\t;; tail recursion means no push lr/pop pc, and we can use the direct return\n\n4: all this is very academic since most of the time will be in the div operation anyway...\n\n;; x86 version for comparison\n\ngcd:\t\t\t\t\t; expects a in edi, b in esi\n\tmov\teax, edi\n\ttest\t\tesi, esi\n\tjz\t\t.out\t\t\t;; no conditional return\n.loop:\n\txor\t\tedx, edx\t\t;; top half of dividand must be zeroed\n\tdiv\t\tesi\t\t\t;; div takes edx:eax as dividand, returns quotient in eax and remainder in edx\n\tmov\teax, esi\n\tmov\tesi, edx\n\ttest\t\tedx, edx\t\t;; have to use dedicated instruction for setting flags\n\tjnz\t\t.loop\t\t;; but at least these test/branch combo's get turned into a single µop when executed\n.out:\n\tret\t\t\t\t\t; return is in eax\n\n;;; the iterative logic as C\n\nint gcd(int a, int b) {\n\tif(!b) return a;\n\tint c;\n\twhile(c = a % b) { a = b; b = c; }\n\treturn b;\n}","author":"@treelibrarian7618","author_id":"UCFXKR8B0LqYQAGXNLWOuzBw","like_count":89,"published_time":"2 years ago"},{"id":"UgyKnvK90V3kgVl-wpd4AaABAg","text":"I don't know what the heckin flip I'm watching but I freakin know it's epic dude.","author":"@jonasc1221","author_id":"UC0-NCPzaT7XjGFdXAT4uXrA","like_count":1,"published_time":"2 years ago"},{"id":"UgwWLrufjJ5sbLDCkxF4AaABAg","text":"just in case, the modulo implementation works out if you use integer division not \"normal\" division\n(2//5)*5=0, but (2/5)*5=2","author":"@maydude2","author_id":"UCminbZdDmzr4QsUH1B5Fwyg","like_count":6,"published_time":"2 years ago"},{"id":"UgwEkRVspJzaseKBgLB4AaABAg","text":"Very nice walk-through! Small tip: if you ‘:set autoindent expandtab tabstop=8’, you can then use the <TAB> key to indent with spaces, and you will have a nicer vim experience.","author":"@edgarbonet1","author_id":"UC9KL7XU5j5HX-FbEJKJPtlg","like_count":1,"published_time":"11 months ago"},{"id":"UgxI0UdR8HAuTIewPzp4AaABAg","text":"looking for YouTuber making tutorial about arm assembly, never found, and tonight YouTube recommended this channel, okay YouTube, okay","author":"@hlodvic6678","author_id":"UCpvr8OL9OqXpkTIVp_y-Kxg","like_count":1,"published_time":"2 years ago"},{"id":"Ugw1I89X4X0aVw37Brp4AaABAg","text":"Everybody who comments \"the algorithm brought me here\" needs to immediately like and subscribe. Thats how we can boost channels like this","author":"@gcrannell","author_id":"UCpnZDR1AXRsYtMcDw35hQHw","like_count":1,"published_time":"2 years ago"},{"id":"UgyQ5xOf7YTmJLDvagR4AaABAg","text":"I have been watching tech and programming channels for many years. This is the first time YouTube has recommended you. Glad to see it!","author":"@PaulEmsley","author_id":"UCbHAnhn_6MOmmjMMhR_0qkQ","like_count":10,"published_time":"2 years ago"},{"id":"UgxQn1SKh8yO_ciQy_54AaABAg","text":"weird way to propose but yes I accept","author":"@eduardoignacioroblessosa6349","author_id":"UCSDgxJoiZWswDOpph8sGn9w","like_count":2,"published_time":"2 years ago"},{"id":"UgyDOiM-YIy5EaE6ouZ4AaABAg","text":"OMG. Last time I wrote assembly was like 20 years ago! I love this woman!","author":"@sushiConPorotos","author_id":"UC1V0DFx7BlfCI9xVKPgQsOA","like_count":10,"published_time":"2 years ago"},{"id":"UgyHWJWuOK-uTLDe3yF4AaABAg","text":"I last coded in Arm for an Acorn Archimedes about 35 years ago. Thanks for the memory jolt.","author":"@CrestRising","author_id":"UCWbsTFBqosZXS2J_P-j4XCQ","like_count":1,"published_time":"2 years ago"},{"id":"Ugzv0nPUexcaoURHiRF4AaABAg","text":"Serial Experiments Lain! And the Wired. Wow!!! 😳 Awesome references. Just stumbled on this channel, so I wanted to acknowledge that. 😊","author":"@traal","author_id":"UC8kVxpH5j7I_613bRZ_d5ig","like_count":32,"published_time":"2 years ago"},{"id":"UgyKSncBdPsNdD792dx4AaABAg","text":"As someone who subscribes to a ton of tech-related channels, this is the first time YouTube recommended me to this channel.","author":"@chyldstudios","author_id":"UCoxgRBEk_fIKnlg_Qx8ughQ","like_count":396,"published_time":"2 years ago"},{"id":"Ugyt6Z4xGrMspdGvyKx4AaABAg","text":"Easily the greatest common divisor in the history of all common divisors","author":"@maisylover","author_id":"UCO_UB8B3SZ2M0uPZ0gp9aKQ","like_count":252,"published_time":"2 years ago"},{"id":"Ugx2A2jKZ5xI6NegQyl4AaABAg","text":"I was looking for something to snooze to and thought this was ASMR Assembly.","author":"@maelstrom57","author_id":"UC9BJqAqRlOJBAA0O4WYSmnw","like_count":77,"published_time":"2 years ago"},{"id":"UgxEwA0HYsWpnm94ol14AaABAg","text":"This is a great introduction and walk through for newcomers to assembly, but beware that the implementation has a quite significant flaw that will only reveal itself when called from other functions that have several live registers and happen to use r4 and store a value in it when it makes the call to this gcd function. The calling function will expect that the gcd function preserves the r4 register, as it is not a scratch register like r0-r3 are. This will manifest in miscalculations, unpredictable behavior and likely instability/crashes in the application using this function. An easy fix would be to push the r4 register along with lr to the stack, and pop it again (i.e. push {r4, lr} - pop {r4, pc}), but this of course increases the stack usage even more. Another approach would be to use r12 which is also a scratch register.\n\nIt would also be a good idea to make the implementation non-recursive as it can overflow the stack if it recurses too many times. For this algorithm this is quite easy as you can do tail call optimization by simply removing the push, replacing the pop by \"bx lr\" and doing a \"b gcd\" instead of \"bl gcd\" (which means the lr does not get overwritten for each iteration and retains the original return address that was written when the function was called the first time). This means the stack won't grow for each iteration.","author":"@ThomasThorsen","author_id":"UCrnn5DYsdOmhT13aXqqsUUg","like_count":97,"published_time":"2 years ago"},{"id":"UgwNKziAUmlG6AXRII14AaABAg","text":"praise the algorithm gods... how am i only just learning about this channel?","author":"@gcrannell","author_id":"UCpnZDR1AXRsYtMcDw35hQHw","like_count":48,"published_time":"2 years ago"},{"id":"UgydkMM5TmT0NWFIDOJ4AaABAg","text":"I finally watch Lain and now the Youtube algorithm is rewarding me","author":"@Summanis","author_id":"UC9hG-mlN6ktivoTLV7snN9Q","like_count":84,"published_time":"2 years ago"},{"id":"Ugz-7QdxrX4u307hjx14AaABAg","text":"I love the XP rice 😂","author":"@thejintent2770","author_id":"UCo_w3QOCgmvgW0bP6nyWlLw","like_count":10,"published_time":"2 years ago"},{"id":"UgzUmGw6JCivvaTQ6Ml4AaABAg","text":"Underrated channel. I cannot wait to get fat enough in my CS courses to understand this","author":"@mebibyte9347","author_id":"UCdhqpME4X4_bQB9Esg7pCtw","like_count":89,"published_time":"2 years ago"},{"id":"UgzbfKnwxE7CD2fZxQ54AaABAg","text":"The quality of the video and the content is top notch. Here before 1 M subscribers","author":"@ogphoenix8965","author_id":"UCo6f35f9M3xqAoGKM5OGwfg","like_count":20,"published_time":"2 years ago"},{"id":"UgxKy4C0T-wMsaqh_qp4AaABAg","text":"So it's been a few years since I was last writing in ARM asm (32-bit MCUs), so I might be a bit rusty... but I thought I saw a few tricks you'd missed, opened a notepad and downloaded an arm instruction-set reference and had a go myself. What I noticed:\n\n1: this is an ideal opportunity for tail recursion, simplifying the recursion to effectively a loop and removing the need to unwind the calls from the stack at the end\n2: move can set flags, removing the need to compare to determine zero both on entry and within the loop\n3: once you don't need to push/pop, bx lr can be used to return and can even be used with condition codes\n\n;; arm version\n\ngcd:\n\tmovs\tr1, r1\t\t;; mov can set flags? easiest way to get the z flag set for a zero input?\n\tbxeq\tlr\t\t\t;; conditional return. nice. assumes A32 instruction set tho...\n.loop:\n\tsdiv\t\tr2, r0, r1\t\t;; I find it surprising that ARM doesn't have some way to return\n\tmul\t\tr2, r2, r1\t\t;;  the remainder from a division... the bits are right there at the\n\tsub\t\tr2, r0, r2\t\t;;  end of the process, but then they get lost? and I have to recompute them? smh.\n\tmov\tr0, r1\t\t;; but even so, the ARM version is still smaller and neater than the x86,\n\tmovs\tr1, r2\t\t;;  which has to dance around the fixed register usage of its DIV instruction\n\tbne\t\tloop\t\t;; mov setting flags means that we can conditionally loop - also could set flags on the sub\n\tbx\t\tlr\t\t\t;; tail recursion means no push lr/pop pc, and we can use the direct return\n\n4: all this is very academic since most of the time will be in the div operation anyway...\n\n;; x86 version for comparison\n\ngcd:\t\t\t\t\t; expects a in edi, b in esi\n\tmov\teax, edi\n\ttest\t\tesi, esi\n\tjz\t\t.out\t\t\t;; no conditional return\n.loop:\n\txor\t\tedx, edx\t\t;; top half of dividand must be zeroed\n\tdiv\t\tesi\t\t\t;; div takes edx:eax as dividand, returns quotient in eax and remainder in edx\n\tmov\teax, esi\n\tmov\tesi, edx\n\ttest\t\tedx, edx\t\t;; have to use dedicated instruction for setting flags\n\tjnz\t\t.loop\t\t;; but at least these test/branch combo's get turned into a single µop when executed\n.out:\n\tret\t\t\t\t\t; return is in eax\n\n;;; the iterative logic as C\n\nint gcd(int a, int b) {\n\tif(!b) return a;\n\tint c;\n\twhile(c = a % b) { a = b; b = c; }\n\treturn b;\n}","author":"@treelibrarian7618","author_id":"UCFXKR8B0LqYQAGXNLWOuzBw","like_count":89,"published_time":"2 years ago"},{"id":"UgyKnvK90V3kgVl-wpd4AaABAg","text":"I don't know what the heckin flip I'm watching but I freakin know it's epic dude.","author":"@jonasc1221","author_id":"UC0-NCPzaT7XjGFdXAT4uXrA","like_count":1,"published_time":"2 years ago"},{"id":"UgwWLrufjJ5sbLDCkxF4AaABAg","text":"just in case, the modulo implementation works out if you use integer division not \"normal\" division\n(2//5)*5=0, but (2/5)*5=2","author":"@maydude2","author_id":"UCminbZdDmzr4QsUH1B5Fwyg","like_count":6,"published_time":"2 years ago"},{"id":"UgwEkRVspJzaseKBgLB4AaABAg","text":"Very nice walk-through! Small tip: if you ‘:set autoindent expandtab tabstop=8’, you can then use the <TAB> key to indent with spaces, and you will have a nicer vim experience.","author":"@edgarbonet1","author_id":"UC9KL7XU5j5HX-FbEJKJPtlg","like_count":1,"published_time":"11 months ago"},{"id":"Ugw1I89X4X0aVw37Brp4AaABAg","text":"Everybody who comments \"the algorithm brought me here\" needs to immediately like and subscribe. Thats how we can boost channels like this","author":"@gcrannell","author_id":"UCpnZDR1AXRsYtMcDw35hQHw","like_count":1,"published_time":"2 years ago"},{"id":"UgxI0UdR8HAuTIewPzp4AaABAg","text":"looking for YouTuber making tutorial about arm assembly, never found, and tonight YouTube recommended this channel, okay YouTube, okay","author":"@hlodvic6678","author_id":"UCpvr8OL9OqXpkTIVp_y-Kxg","like_count":1,"published_time":"2 years ago"},{"id":"UgyQ5xOf7YTmJLDvagR4AaABAg","text":"I have been watching tech and programming channels for many years. This is the first time YouTube has recommended you. Glad to see it!","author":"@PaulEmsley","author_id":"UCbHAnhn_6MOmmjMMhR_0qkQ","like_count":10,"published_time":"2 years ago"},{"id":"UgxQn1SKh8yO_ciQy_54AaABAg","text":"weird way to propose but yes I accept","author":"@eduardoignacioroblessosa6349","author_id":"UCSDgxJoiZWswDOpph8sGn9w","like_count":2,"published_time":"2 years ago"},{"id":"UgyDOiM-YIy5EaE6ouZ4AaABAg","text":"OMG. Last time I wrote assembly was like 20 years ago! I love this woman!","author":"@sushiConPorotos","author_id":"UC1V0DFx7BlfCI9xVKPgQsOA","like_count":10,"published_time":"2 years ago"},{"id":"UgyHWJWuOK-uTLDe3yF4AaABAg","text":"I last coded in Arm for an Acorn Archimedes about 35 years ago. Thanks for the memory jolt.","author":"@CrestRising","author_id":"UCWbsTFBqosZXS2J_P-j4XCQ","like_count":1,"published_time":"2 years ago"},{"id":"Ugzv0nPUexcaoURHiRF4AaABAg","text":"Serial Experiments Lain! And the Wired. Wow!!! 😳 Awesome references. Just stumbled on this channel, so I wanted to acknowledge that. 😊","author":"@traal","author_id":"UC8kVxpH5j7I_613bRZ_d5ig","like_count":32,"published_time":"2 years ago"},{"id":"UgyKSncBdPsNdD792dx4AaABAg","text":"As someone who subscribes to a ton of tech-related channels, this is the first time YouTube recommended me to this channel.","author":"@chyldstudios","author_id":"UCoxgRBEk_fIKnlg_Qx8ughQ","like_count":396,"published_time":"2 years ago"},{"id":"Ugyt6Z4xGrMspdGvyKx4AaABAg","text":"Easily the greatest common divisor in the history of all common divisors","author":"@maisylover","author_id":"UCO_UB8B3SZ2M0uPZ0gp9aKQ","like_count":252,"published_time":"2 years ago"},{"id":"Ugx2A2jKZ5xI6NegQyl4AaABAg","text":"I was looking for something to snooze to and thought this was ASMR Assembly.","author":"@maelstrom57","author_id":"UC9BJqAqRlOJBAA0O4WYSmnw","like_count":77,"published_time":"2 years ago"},{"id":"UgxEwA0HYsWpnm94ol14AaABAg","text":"This is a great introduction and walk through for newcomers to assembly, but beware that the implementation has a quite significant flaw that will only reveal itself when called from other functions that have several live registers and happen to use r4 and store a value in it when it makes the call to this gcd function. The calling function will expect that the gcd function preserves the r4 register, as it is not a scratch register like r0-r3 are. This will manifest in miscalculations, unpredictable behavior and likely instability/crashes in the application using this function. An easy fix would be to push the r4 register along with lr to the stack, and pop it again (i.e. push {r4, lr} - pop {r4, pc}), but this of course increases the stack usage even more. Another approach would be to use r12 which is also a scratch register.\n\nIt would also be a good idea to make the implementation non-recursive as it can overflow the stack if it recurses too many times. For this algorithm this is quite easy as you can do tail call optimization by simply removing the push, replacing the pop by \"bx lr\" and doing a \"b gcd\" instead of \"bl gcd\" (which means the lr does not get overwritten for each iteration and retains the original return address that was written when the function was called the first time). This means the stack won't grow for each iteration.","author":"@ThomasThorsen","author_id":"UCrnn5DYsdOmhT13aXqqsUUg","like_count":97,"published_time":"2 years ago"},{"id":"UgwNKziAUmlG6AXRII14AaABAg","text":"praise the algorithm gods... how am i only just learning about this channel?","author":"@gcrannell","author_id":"UCpnZDR1AXRsYtMcDw35hQHw","like_count":48,"published_time":"2 years ago"},{"id":"UgydkMM5TmT0NWFIDOJ4AaABAg","text":"I finally watch Lain and now the Youtube algorithm is rewarding me","author":"@Summanis","author_id":"UC9hG-mlN6ktivoTLV7snN9Q","like_count":84,"published_time":"2 years ago"},{"id":"Ugz-7QdxrX4u307hjx14AaABAg","text":"I love the XP rice 😂","author":"@thejintent2770","author_id":"UCo_w3QOCgmvgW0bP6nyWlLw","like_count":10,"published_time":"2 years ago"},{"id":"UgzUmGw6JCivvaTQ6Ml4AaABAg","text":"Underrated channel. I cannot wait to get fat enough in my CS courses to understand this","author":"@mebibyte9347","author_id":"UCdhqpME4X4_bQB9Esg7pCtw","like_count":89,"published_time":"2 years ago"},{"id":"UgzbfKnwxE7CD2fZxQ54AaABAg","text":"The quality of the video and the content is top notch. Here before 1 M subscribers","author":"@ogphoenix8965","author_id":"UCo6f35f9M3xqAoGKM5OGwfg","like_count":20,"published_time":"2 years ago"},{"id":"UgxKy4C0T-wMsaqh_qp4AaABAg","text":"So it's been a few years since I was last writing in ARM asm (32-bit MCUs), so I might be a bit rusty... but I thought I saw a few tricks you'd missed, opened a notepad and downloaded an arm instruction-set reference and had a go myself. What I noticed:\n\n1: this is an ideal opportunity for tail recursion, simplifying the recursion to effectively a loop and removing the need to unwind the calls from the stack at the end\n2: move can set flags, removing the need to compare to determine zero both on entry and within the loop\n3: once you don't need to push/pop, bx lr can be used to return and can even be used with condition codes\n\n;; arm version\n\ngcd:\n\tmovs\tr1, r1\t\t;; mov can set flags? easiest way to get the z flag set for a zero input?\n\tbxeq\tlr\t\t\t;; conditional return. nice. assumes A32 instruction set tho...\n.loop:\n\tsdiv\t\tr2, r0, r1\t\t;; I find it surprising that ARM doesn't have some way to return\n\tmul\t\tr2, r2, r1\t\t;;  the remainder from a division... the bits are right there at the\n\tsub\t\tr2, r0, r2\t\t;;  end of the process, but then they get lost? and I have to recompute them? smh.\n\tmov\tr0, r1\t\t;; but even so, the ARM version is still smaller and neater than the x86,\n\tmovs\tr1, r2\t\t;;  which has to dance around the fixed register usage of its DIV instruction\n\tbne\t\tloop\t\t;; mov setting flags means that we can conditionally loop - also could set flags on the sub\n\tbx\t\tlr\t\t\t;; tail recursion means no push lr/pop pc, and we can use the direct return\n\n4: all this is very academic since most of the time will be in the div operation anyway...\n\n;; x86 version for comparison\n\ngcd:\t\t\t\t\t; expects a in edi, b in esi\n\tmov\teax, edi\n\ttest\t\tesi, esi\n\tjz\t\t.out\t\t\t;; no conditional return\n.loop:\n\txor\t\tedx, edx\t\t;; top half of dividand must be zeroed\n\tdiv\t\tesi\t\t\t;; div takes edx:eax as dividand, returns quotient in eax and remainder in edx\n\tmov\teax, esi\n\tmov\tesi, edx\n\ttest\t\tedx, edx\t\t;; have to use dedicated instruction for setting flags\n\tjnz\t\t.loop\t\t;; but at least these test/branch combo's get turned into a single µop when executed\n.out:\n\tret\t\t\t\t\t; return is in eax\n\n;;; the iterative logic as C\n\nint gcd(int a, int b) {\n\tif(!b) return a;\n\tint c;\n\twhile(c = a % b) { a = b; b = c; }\n\treturn b;\n}","author":"@treelibrarian7618","author_id":"UCFXKR8B0LqYQAGXNLWOuzBw","like_count":89,"published_time":"2 years ago"},{"id":"UgyKnvK90V3kgVl-wpd4AaABAg","text":"I don't know what the heckin flip I'm watching but I freakin know it's epic dude.","author":"@jonasc1221","author_id":"UC0-NCPzaT7XjGFdXAT4uXrA","like_count":1,"published_time":"2 years ago"},{"id":"UgwWLrufjJ5sbLDCkxF4AaABAg","text":"just in case, the modulo implementation works out if you use integer division not \"normal\" division\n(2//5)*5=0, but (2/5)*5=2","author":"@maydude2","author_id":"UCminbZdDmzr4QsUH1B5Fwyg","like_count":6,"published_time":"2 years ago"},{"id":"UgwEkRVspJzaseKBgLB4AaABAg","text":"Very nice walk-through! Small tip: if you ‘:set autoindent expandtab tabstop=8’, you can then use the <TAB> key to indent with spaces, and you will have a nicer vim experience.","author":"@edgarbonet1","author_id":"UC9KL7XU5j5HX-FbEJKJPtlg","like_count":1,"published_time":"11 months ago"},{"id":"UgxI0UdR8HAuTIewPzp4AaABAg","text":"looking for YouTuber making tutorial about arm assembly, never found, and tonight YouTube recommended this channel, okay YouTube, okay","author":"@hlodvic6678","author_id":"UCpvr8OL9OqXpkTIVp_y-Kxg","like_count":1,"published_time":"2 years ago"},{"id":"Ugw1I89X4X0aVw37Brp4AaABAg","text":"Everybody who comments \"the algorithm brought me here\" needs to immediately like and subscribe. Thats how we can boost channels like this","author":"@gcrannell","author_id":"UCpnZDR1AXRsYtMcDw35hQHw","like_count":1,"published_time":"2 years ago"},{"id":"UgyQ5xOf7YTmJLDvagR4AaABAg","text":"I have been watching tech and programming channels for many years. This is the first time YouTube has recommended you. Glad to see it!","author":"@PaulEmsley","author_id":"UCbHAnhn_6MOmmjMMhR_0qkQ","like_count":10,"published_time":"2 years ago"},{"id":"UgxQn1SKh8yO_ciQy_54AaABAg","text":"weird way to propose but yes I accept","author":"@eduardoignacioroblessosa6349","author_id":"UCSDgxJoiZWswDOpph8sGn9w","like_count":2,"published_time":"2 years ago"},{"id":"UgyDOiM-YIy5EaE6ouZ4AaABAg","text":"OMG. Last time I wrote assembly was like 20 years ago! I love this woman!","author":"@sushiConPorotos","author_id":"UC1V0DFx7BlfCI9xVKPgQsOA","like_count":10,"published_time":"2 years ago"},{"id":"UgyHWJWuOK-uTLDe3yF4AaABAg","text":"I last coded in Arm for an Acorn Archimedes about 35 years ago. Thanks for the memory jolt.","author":"@CrestRising","author_id":"UCWbsTFBqosZXS2J_P-j4XCQ","like_count":1,"published_time":"2 years ago"},{"id":"Ugzv0nPUexcaoURHiRF4AaABAg","text":"Serial Experiments Lain! And the Wired. Wow!!! 😳 Awesome references. Just stumbled on this channel, so I wanted to acknowledge that. 😊","author":"@traal","author_id":"UC8kVxpH5j7I_613bRZ_d5ig","like_count":32,"published_time":"2 years ago"},{"id":"UgyKSncBdPsNdD792dx4AaABAg","text":"As someone who subscribes to a ton of tech-related channels, this is the first time YouTube recommended me to this channel.","author":"@chyldstudios","author_id":"UCoxgRBEk_fIKnlg_Qx8ughQ","like_count":396,"published_time":"2 years ago"},{"id":"Ugyt6Z4xGrMspdGvyKx4AaABAg","text":"Easily the greatest common divisor in the history of all common divisors","author":"@maisylover","author_id":"UCO_UB8B3SZ2M0uPZ0gp9aKQ","like_count":252,"published_time":"2 years ago"},{"id":"Ugx2A2jKZ5xI6NegQyl4AaABAg","text":"I was looking for something to snooze to and thought this was ASMR Assembly.","author":"@maelstrom57","author_id":"UC9BJqAqRlOJBAA0O4WYSmnw","like_count":77,"published_time":"2 years ago"},{"id":"UgxEwA0HYsWpnm94ol14AaABAg","text":"This is a great introduction and walk through for newcomers to assembly, but beware that the implementation has a quite significant flaw that will only reveal itself when called from other functions that have several live registers and happen to use r4 and store a value in it when it makes the call to this gcd function. The calling function will expect that the gcd function preserves the r4 register, as it is not a scratch register like r0-r3 are. This will manifest in miscalculations, unpredictable behavior and likely instability/crashes in the application using this function. An easy fix would be to push the r4 register along with lr to the stack, and pop it again (i.e. push {r4, lr} - pop {r4, pc}), but this of course increases the stack usage even more. Another approach would be to use r12 which is also a scratch register.\n\nIt would also be a good idea to make the implementation non-recursive as it can overflow the stack if it recurses too many times. For this algorithm this is quite easy as you can do tail call optimization by simply removing the push, replacing the pop by \"bx lr\" and doing a \"b gcd\" instead of \"bl gcd\" (which means the lr does not get overwritten for each iteration and retains the original return address that was written when the function was called the first time). This means the stack won't grow for each iteration.","author":"@ThomasThorsen","author_id":"UCrnn5DYsdOmhT13aXqqsUUg","like_count":97,"published_time":"2 years ago"},{"id":"UgwNKziAUmlG6AXRII14AaABAg","text":"praise the algorithm gods... how am i only just learning about this channel?","author":"@gcrannell","author_id":"UCpnZDR1AXRsYtMcDw35hQHw","like_count":48,"published_time":"2 years ago"},{"id":"UgydkMM5TmT0NWFIDOJ4AaABAg","text":"I finally watch Lain and now the Youtube algorithm is rewarding me","author":"@Summanis","author_id":"UC9hG-mlN6ktivoTLV7snN9Q","like_count":84,"published_time":"2 years ago"},{"id":"Ugz-7QdxrX4u307hjx14AaABAg","text":"I love the XP rice 😂","author":"@thejintent2770","author_id":"UCo_w3QOCgmvgW0bP6nyWlLw","like_count":10,"published_time":"2 years ago"},{"id":"UgzUmGw6JCivvaTQ6Ml4AaABAg","text":"Underrated channel. I cannot wait to get fat enough in my CS courses to understand this","author":"@mebibyte9347","author_id":"UCdhqpME4X4_bQB9Esg7pCtw","like_count":89,"published_time":"2 years ago"},{"id":"UgzbfKnwxE7CD2fZxQ54AaABAg","text":"The quality of the video and the content is top notch. Here before 1 M subscribers","author":"@ogphoenix8965","author_id":"UCo6f35f9M3xqAoGKM5OGwfg","like_count":20,"published_time":"2 years ago"},{"id":"UgxKy4C0T-wMsaqh_qp4AaABAg","text":"So it's been a few years since I was last writing in ARM asm (32-bit MCUs), so I might be a bit rusty... but I thought I saw a few tricks you'd missed, opened a notepad and downloaded an arm instruction-set reference and had a go myself. What I noticed:\n\n1: this is an ideal opportunity for tail recursion, simplifying the recursion to effectively a loop and removing the need to unwind the calls from the stack at the end\n2: move can set flags, removing the need to compare to determine zero both on entry and within the loop\n3: once you don't need to push/pop, bx lr can be used to return and can even be used with condition codes\n\n;; arm version\n\ngcd:\n\tmovs\tr1, r1\t\t;; mov can set flags? easiest way to get the z flag set for a zero input?\n\tbxeq\tlr\t\t\t;; conditional return. nice. assumes A32 instruction set tho...\n.loop:\n\tsdiv\t\tr2, r0, r1\t\t;; I find it surprising that ARM doesn't have some way to return\n\tmul\t\tr2, r2, r1\t\t;;  the remainder from a division... the bits are right there at the\n\tsub\t\tr2, r0, r2\t\t;;  end of the process, but then they get lost? and I have to recompute them? smh.\n\tmov\tr0, r1\t\t;; but even so, the ARM version is still smaller and neater than the x86,\n\tmovs\tr1, r2\t\t;;  which has to dance around the fixed register usage of its DIV instruction\n\tbne\t\tloop\t\t;; mov setting flags means that we can conditionally loop - also could set flags on the sub\n\tbx\t\tlr\t\t\t;; tail recursion means no push lr/pop pc, and we can use the direct return\n\n4: all this is very academic since most of the time will be in the div operation anyway...\n\n;; x86 version for comparison\n\ngcd:\t\t\t\t\t; expects a in edi, b in esi\n\tmov\teax, edi\n\ttest\t\tesi, esi\n\tjz\t\t.out\t\t\t;; no conditional return\n.loop:\n\txor\t\tedx, edx\t\t;; top half of dividand must be zeroed\n\tdiv\t\tesi\t\t\t;; div takes edx:eax as dividand, returns quotient in eax and remainder in edx\n\tmov\teax, esi\n\tmov\tesi, edx\n\ttest\t\tedx, edx\t\t;; have to use dedicated instruction for setting flags\n\tjnz\t\t.loop\t\t;; but at least these test/branch combo's get turned into a single µop when executed\n.out:\n\tret\t\t\t\t\t; return is in eax\n\n;;; the iterative logic as C\n\nint gcd(int a, int b) {\n\tif(!b) return a;\n\tint c;\n\twhile(c = a % b) { a = b; b = c; }\n\treturn b;\n}","author":"@treelibrarian7618","author_id":"UCFXKR8B0LqYQAGXNLWOuzBw","like_count":89,"published_time":"2 years ago"},{"id":"UgyKnvK90V3kgVl-wpd4AaABAg","text":"I don't know what the heckin flip I'm watching but I freakin know it's epic dude.","author":"@jonasc1221","author_id":"UC0-NCPzaT7XjGFdXAT4uXrA","like_count":1,"published_time":"2 years ago"},{"id":"UgwWLrufjJ5sbLDCkxF4AaABAg","text":"just in case, the modulo implementation works out if you use integer division not \"normal\" division\n(2//5)*5=0, but (2/5)*5=2","author":"@maydude2","author_id":"UCminbZdDmzr4QsUH1B5Fwyg","like_count":6,"published_time":"2 years ago"},{"id":"UgwEkRVspJzaseKBgLB4AaABAg","text":"Very nice walk-through! Small tip: if you ‘:set autoindent expandtab tabstop=8’, you can then use the <TAB> key to indent with spaces, and you will have a nicer vim experience.","author":"@edgarbonet1","author_id":"UC9KL7XU5j5HX-FbEJKJPtlg","like_count":1,"published_time":"11 months ago"},{"id":"UgxI0UdR8HAuTIewPzp4AaABAg","text":"looking for YouTuber making tutorial about arm assembly, never found, and tonight YouTube recommended this channel, okay YouTube, okay","author":"@hlodvic6678","author_id":"UCpvr8OL9OqXpkTIVp_y-Kxg","like_count":1,"published_time":"2 years ago"},{"id":"Ugw1I89X4X0aVw37Brp4AaABAg","text":"Everybody who comments \"the algorithm brought me here\" needs to immediately like and subscribe. Thats how we can boost channels like this","author":"@gcrannell","author_id":"UCpnZDR1AXRsYtMcDw35hQHw","like_count":1,"published_time":"2 years ago"},{"id":"UgyQ5xOf7YTmJLDvagR4AaABAg","text":"I have been watching tech and programming channels for many years. This is the first time YouTube has recommended you. Glad to see it!","author":"@PaulEmsley","author_id":"UCbHAnhn_6MOmmjMMhR_0qkQ","like_count":10,"published_time":"2 years ago"},{"id":"UgxQn1SKh8yO_ciQy_54AaABAg","text":"weird way to propose but yes I accept","author":"@eduardoignacioroblessosa6349","author_id":"UCSDgxJoiZWswDOpph8sGn9w","like_count":2,"published_time":"2 years ago"},{"id":"UgyDOiM-YIy5EaE6ouZ4AaABAg","text":"OMG. Last time I wrote assembly was like 20 years ago! I love this woman!","author":"@sushiConPorotos","author_id":"UC1V0DFx7BlfCI9xVKPgQsOA","like_count":10,"published_time":"2 years ago"},{"id":"UgyHWJWuOK-uTLDe3yF4AaABAg","text":"I last coded in Arm for an Acorn Archimedes about 35 years ago. Thanks for the memory jolt.","author":"@CrestRising","author_id":"UCWbsTFBqosZXS2J_P-j4XCQ","like_count":1,"published_time":"2 years ago"},{"id":"Ugzv0nPUexcaoURHiRF4AaABAg","text":"Serial Experiments Lain! And the Wired. Wow!!! 😳 Awesome references. Just stumbled on this channel, so I wanted to acknowledge that. 😊","author":"@traal","author_id":"UC8kVxpH5j7I_613bRZ_d5ig","like_count":32,"published_time":"2 years ago"},{"id":"Ugyt6Z4xGrMspdGvyKx4AaABAg","text":"Easily the greatest common divisor in the history of all common divisors","author":"@maisylover","author_id":"UCO_UB8B3SZ2M0uPZ0gp9aKQ","like_count":252,"published_time":"2 years ago"},{"id":"UgyKSncBdPsNdD792dx4AaABAg","text":"As someone who subscribes to a ton of tech-related channels, this is the first time YouTube recommended me to this channel.","author":"@chyldstudios","author_id":"UCoxgRBEk_fIKnlg_Qx8ughQ","like_count":396,"published_time":"2 years ago"},{"id":"Ugx2A2jKZ5xI6NegQyl4AaABAg","text":"I was looking for something to snooze to and thought this was ASMR Assembly.","author":"@maelstrom57","author_id":"UC9BJqAqRlOJBAA0O4WYSmnw","like_count":77,"published_time":"2 years ago"},{"id":"UgxEwA0HYsWpnm94ol14AaABAg","text":"This is a great introduction and walk through for newcomers to assembly, but beware that the implementation has a quite significant flaw that will only reveal itself when called from other functions that have several live registers and happen to use r4 and store a value in it when it makes the call to this gcd function. The calling function will expect that the gcd function preserves the r4 register, as it is not a scratch register like r0-r3 are. This will manifest in miscalculations, unpredictable behavior and likely instability/crashes in the application using this function. An easy fix would be to push the r4 register along with lr to the stack, and pop it again (i.e. push {r4, lr} - pop {r4, pc}), but this of course increases the stack usage even more. Another approach would be to use r12 which is also a scratch register.\n\nIt would also be a good idea to make the implementation non-recursive as it can overflow the stack if it recurses too many times. For this algorithm this is quite easy as you can do tail call optimization by simply removing the push, replacing the pop by \"bx lr\" and doing a \"b gcd\" instead of \"bl gcd\" (which means the lr does not get overwritten for each iteration and retains the original return address that was written when the function was called the first time). This means the stack won't grow for each iteration.","author":"@ThomasThorsen","author_id":"UCrnn5DYsdOmhT13aXqqsUUg","like_count":97,"published_time":"2 years ago"},{"id":"UgzbfKnwxE7CD2fZxQ54AaABAg","text":"The quality of the video and the content is top notch. Here before 1 M subscribers","author":"@ogphoenix8965","author_id":"UCo6f35f9M3xqAoGKM5OGwfg","like_count":20,"published_time":"2 years ago"},{"id":"Ugz-7QdxrX4u307hjx14AaABAg","text":"I love the XP rice 😂","author":"@thejintent2770","author_id":"UCo_w3QOCgmvgW0bP6nyWlLw","like_count":10,"published_time":"2 years ago"},{"id":"UgwNKziAUmlG6AXRII14AaABAg","text":"praise the algorithm gods... how am i only just learning about this channel?","author":"@gcrannell","author_id":"UCpnZDR1AXRsYtMcDw35hQHw","like_count":48,"published_time":"2 years ago"},{"id":"Ugw1I89X4X0aVw37Brp4AaABAg","text":"Everybody who comments \"the algorithm brought me here\" needs to immediately like and subscribe. Thats how we can boost channels like this","author":"@gcrannell","author_id":"UCpnZDR1AXRsYtMcDw35hQHw","like_count":1,"published_time":"2 years ago"},{"id":"UgyKnvK90V3kgVl-wpd4AaABAg","text":"I don't know what the heckin flip I'm watching but I freakin know it's epic dude.","author":"@jonasc1221","author_id":"UC0-NCPzaT7XjGFdXAT4uXrA","like_count":1,"published_time":"2 years ago"},{"id":"UgydkMM5TmT0NWFIDOJ4AaABAg","text":"I finally watch Lain and now the Youtube algorithm is rewarding me","author":"@Summanis","author_id":"UC9hG-mlN6ktivoTLV7snN9Q","like_count":84,"published_time":"2 years ago"},{"id":"UgxQn1SKh8yO_ciQy_54AaABAg","text":"weird way to propose but yes I accept","author":"@eduardoignacioroblessosa6349","author_id":"UCSDgxJoiZWswDOpph8sGn9w","like_count":2,"published_time":"2 years ago"},{"id":"UgxI0UdR8HAuTIewPzp4AaABAg","text":"looking for YouTuber making tutorial about arm assembly, never found, and tonight YouTube recommended this channel, okay YouTube, okay","author":"@hlodvic6678","author_id":"UCpvr8OL9OqXpkTIVp_y-Kxg","like_count":1,"published_time":"2 years ago"},{"id":"UgzUmGw6JCivvaTQ6Ml4AaABAg","text":"Underrated channel. I cannot wait to get fat enough in my CS courses to understand this","author":"@mebibyte9347","author_id":"UCdhqpME4X4_bQB9Esg7pCtw","like_count":89,"published_time":"2 years ago"},{"id":"UgwEkRVspJzaseKBgLB4AaABAg","text":"Very nice walk-through! Small tip: if you ‘:set autoindent expandtab tabstop=8’, you can then use the <TAB> key to indent with spaces, and you will have a nicer vim experience.","author":"@edgarbonet1","author_id":"UC9KL7XU5j5HX-FbEJKJPtlg","like_count":1,"published_time":"11 months ago"},{"id":"UgyQ5xOf7YTmJLDvagR4AaABAg","text":"I have been watching tech and programming channels for many years. This is the first time YouTube has recommended you. Glad to see it!","author":"@PaulEmsley","author_id":"UCbHAnhn_6MOmmjMMhR_0qkQ","like_count":10,"published_time":"2 years ago"},{"id":"Ugyfje5VGCaYkZjTujR4AaABAg","text":"I feel like Laurie must have a really cool dad","author":"@fignuuuts","author_id":"UC6JtSRDcxaUMfxvKbBz3hdQ","like_count":1,"published_time":"2 years ago"},{"id":"UgwWLrufjJ5sbLDCkxF4AaABAg","text":"just in case, the modulo implementation works out if you use integer division not \"normal\" division\n(2//5)*5=0, but (2/5)*5=2","author":"@maydude2","author_id":"UCminbZdDmzr4QsUH1B5Fwyg","like_count":6,"published_time":"2 years ago"},{"id":"UgyM6gnM5Ec2B3WzGw54AaABAg","text":"Laurie you are a computer God! Don't let anyone tell you otherwise. Most of the time I can barely learn what level you are at. You are a pro! Stay awesome Laurie!!","author":"@nitrostatus","author_id":"UC_buEydzsmnQvLAitIw5NXg","like_count":0,"published_time":"1 year ago"},{"id":"Ugx-C__zbo65BP4jh894AaABAg","text":"she's a lain fan 🤩:face-red-heart-shape:","author":"@pawan4920","author_id":"UCTOAMzR2e4JDGXuFe_BETcQ","like_count":1,"published_time":"2 years ago"},{"id":"UgyHWJWuOK-uTLDe3yF4AaABAg","text":"I last coded in Arm for an Acorn Archimedes about 35 years ago. Thanks for the memory jolt.","author":"@CrestRising","author_id":"UCWbsTFBqosZXS2J_P-j4XCQ","like_count":1,"published_time":"2 years ago"},{"id":"UgyKSncBdPsNdD792dx4AaABAg","text":"As someone who subscribes to a ton of tech-related channels, this is the first time YouTube recommended me to this channel.","author":"@chyldstudios","author_id":"UCoxgRBEk_fIKnlg_Qx8ughQ","like_count":396,"published_time":"2 years ago"},{"id":"Ugyt6Z4xGrMspdGvyKx4AaABAg","text":"Easily the greatest common divisor in the history of all common divisors","author":"@maisylover","author_id":"UCO_UB8B3SZ2M0uPZ0gp9aKQ","like_count":252,"published_time":"2 years ago"},{"id":"Ugx2A2jKZ5xI6NegQyl4AaABAg","text":"I was looking for something to snooze to and thought this was ASMR Assembly.","author":"@maelstrom57","author_id":"UC9BJqAqRlOJBAA0O4WYSmnw","like_count":77,"published_time":"2 years ago"},{"id":"UgxEwA0HYsWpnm94ol14AaABAg","text":"This is a great introduction and walk through for newcomers to assembly, but beware that the implementation has a quite significant flaw that will only reveal itself when called from other functions that have several live registers and happen to use r4 and store a value in it when it makes the call to this gcd function. The calling function will expect that the gcd function preserves the r4 register, as it is not a scratch register like r0-r3 are. This will manifest in miscalculations, unpredictable behavior and likely instability/crashes in the application using this function. An easy fix would be to push the r4 register along with lr to the stack, and pop it again (i.e. push {r4, lr} - pop {r4, pc}), but this of course increases the stack usage even more. Another approach would be to use r12 which is also a scratch register.\n\nIt would also be a good idea to make the implementation non-recursive as it can overflow the stack if it recurses too many times. For this algorithm this is quite easy as you can do tail call optimization by simply removing the push, replacing the pop by \"bx lr\" and doing a \"b gcd\" instead of \"bl gcd\" (which means the lr does not get overwritten for each iteration and retains the original return address that was written when the function was called the first time). This means the stack won't grow for each iteration.","author":"@ThomasThorsen","author_id":"UCrnn5DYsdOmhT13aXqqsUUg","like_count":97,"published_time":"2 years ago"},{"id":"UgwNKziAUmlG6AXRII14AaABAg","text":"praise the algorithm gods... how am i only just learning about this channel?","author":"@gcrannell","author_id":"UCpnZDR1AXRsYtMcDw35hQHw","like_count":48,"published_time":"2 years ago"},{"id":"UgydkMM5TmT0NWFIDOJ4AaABAg","text":"I finally watch Lain and now the Youtube algorithm is rewarding me","author":"@Summanis","author_id":"UC9hG-mlN6ktivoTLV7snN9Q","like_count":84,"published_time":"2 years ago"},{"id":"Ugz-7QdxrX4u307hjx14AaABAg","text":"I love the XP rice 😂","author":"@thejintent2770","author_id":"UCo_w3QOCgmvgW0bP6nyWlLw","like_count":10,"published_time":"2 years ago"},{"id":"UgzUmGw6JCivvaTQ6Ml4AaABAg","text":"Underrated channel. I cannot wait to get fat enough in my CS courses to understand this","author":"@mebibyte9347","author_id":"UCdhqpME4X4_bQB9Esg7pCtw","like_count":89,"published_time":"2 years ago"},{"id":"UgzbfKnwxE7CD2fZxQ54AaABAg","text":"The quality of the video and the content is top notch. Here before 1 M subscribers","author":"@ogphoenix8965","author_id":"UCo6f35f9M3xqAoGKM5OGwfg","like_count":20,"published_time":"2 years ago"},{"id":"UgxKy4C0T-wMsaqh_qp4AaABAg","text":"So it's been a few years since I was last writing in ARM asm (32-bit MCUs), so I might be a bit rusty... but I thought I saw a few tricks you'd missed, opened a notepad and downloaded an arm instruction-set reference and had a go myself. What I noticed:\n\n1: this is an ideal opportunity for tail recursion, simplifying the recursion to effectively a loop and removing the need to unwind the calls from the stack at the end\n2: move can set flags, removing the need to compare to determine zero both on entry and within the loop\n3: once you don't need to push/pop, bx lr can be used to return and can even be used with condition codes\n\n;; arm version\n\ngcd:\n\tmovs\tr1, r1\t\t;; mov can set flags? easiest way to get the z flag set for a zero input?\n\tbxeq\tlr\t\t\t;; conditional return. nice. assumes A32 instruction set tho...\n.loop:\n\tsdiv\t\tr2, r0, r1\t\t;; I find it surprising that ARM doesn't have some way to return\n\tmul\t\tr2, r2, r1\t\t;;  the remainder from a division... the bits are right there at the\n\tsub\t\tr2, r0, r2\t\t;;  end of the process, but then they get lost? and I have to recompute them? smh.\n\tmov\tr0, r1\t\t;; but even so, the ARM version is still smaller and neater than the x86,\n\tmovs\tr1, r2\t\t;;  which has to dance around the fixed register usage of its DIV instruction\n\tbne\t\tloop\t\t;; mov setting flags means that we can conditionally loop - also could set flags on the sub\n\tbx\t\tlr\t\t\t;; tail recursion means no push lr/pop pc, and we can use the direct return\n\n4: all this is very academic since most of the time will be in the div operation anyway...\n\n;; x86 version for comparison\n\ngcd:\t\t\t\t\t; expects a in edi, b in esi\n\tmov\teax, edi\n\ttest\t\tesi, esi\n\tjz\t\t.out\t\t\t;; no conditional return\n.loop:\n\txor\t\tedx, edx\t\t;; top half of dividand must be zeroed\n\tdiv\t\tesi\t\t\t;; div takes edx:eax as dividand, returns quotient in eax and remainder in edx\n\tmov\teax, esi\n\tmov\tesi, edx\n\ttest\t\tedx, edx\t\t;; have to use dedicated instruction for setting flags\n\tjnz\t\t.loop\t\t;; but at least these test/branch combo's get turned into a single µop when executed\n.out:\n\tret\t\t\t\t\t; return is in eax\n\n;;; the iterative logic as C\n\nint gcd(int a, int b) {\n\tif(!b) return a;\n\tint c;\n\twhile(c = a % b) { a = b; b = c; }\n\treturn b;\n}","author":"@treelibrarian7618","author_id":"UCFXKR8B0LqYQAGXNLWOuzBw","like_count":89,"published_time":"2 years ago"},{"id":"UgyKnvK90V3kgVl-wpd4AaABAg","text":"I don't know what the heckin flip I'm watching but I freakin know it's epic dude.","author":"@jonasc1221","author_id":"UC0-NCPzaT7XjGFdXAT4uXrA","like_count":1,"published_time":"2 years ago"},{"id":"UgwWLrufjJ5sbLDCkxF4AaABAg","text":"just in case, the modulo implementation works out if you use integer division not \"normal\" division\n(2//5)*5=0, but (2/5)*5=2","author":"@maydude2","author_id":"UCminbZdDmzr4QsUH1B5Fwyg","like_count":6,"published_time":"2 years ago"},{"id":"UgwEkRVspJzaseKBgLB4AaABAg","text":"Very nice walk-through! Small tip: if you ‘:set autoindent expandtab tabstop=8’, you can then use the <TAB> key to indent with spaces, and you will have a nicer vim experience.","author":"@edgarbonet1","author_id":"UC9KL7XU5j5HX-FbEJKJPtlg","like_count":1,"published_time":"11 months ago"},{"id":"UgxI0UdR8HAuTIewPzp4AaABAg","text":"looking for YouTuber making tutorial about arm assembly, never found, and tonight YouTube recommended this channel, okay YouTube, okay","author":"@hlodvic6678","author_id":"UCpvr8OL9OqXpkTIVp_y-Kxg","like_count":1,"published_time":"2 years ago"},{"id":"Ugw1I89X4X0aVw37Brp4AaABAg","text":"Everybody who comments \"the algorithm brought me here\" needs to immediately like and subscribe. Thats how we can boost channels like this","author":"@gcrannell","author_id":"UCpnZDR1AXRsYtMcDw35hQHw","like_count":1,"published_time":"2 years ago"},{"id":"UgyQ5xOf7YTmJLDvagR4AaABAg","text":"I have been watching tech and programming channels for many years. This is the first time YouTube has recommended you. Glad to see it!","author":"@PaulEmsley","author_id":"UCbHAnhn_6MOmmjMMhR_0qkQ","like_count":10,"published_time":"2 years ago"},{"id":"UgxQn1SKh8yO_ciQy_54AaABAg","text":"weird way to propose but yes I accept","author":"@eduardoignacioroblessosa6349","author_id":"UCSDgxJoiZWswDOpph8sGn9w","like_count":2,"published_time":"2 years ago"},{"id":"UgyDOiM-YIy5EaE6ouZ4AaABAg","text":"OMG. Last time I wrote assembly was like 20 years ago! I love this woman!","author":"@sushiConPorotos","author_id":"UC1V0DFx7BlfCI9xVKPgQsOA","like_count":10,"published_time":"2 years ago"},{"id":"UgyHWJWuOK-uTLDe3yF4AaABAg","text":"I last coded in Arm for an Acorn Archimedes about 35 years ago. Thanks for the memory jolt.","author":"@CrestRising","author_id":"UCWbsTFBqosZXS2J_P-j4XCQ","like_count":1,"published_time":"2 years ago"},{"id":"Ugzv0nPUexcaoURHiRF4AaABAg","text":"Serial Experiments Lain! And the Wired. Wow!!! 😳 Awesome references. Just stumbled on this channel, so I wanted to acknowledge that. 😊","author":"@traal","author_id":"UC8kVxpH5j7I_613bRZ_d5ig","like_count":32,"published_time":"2 years ago"},{"id":"UgyKSncBdPsNdD792dx4AaABAg","text":"As someone who subscribes to a ton of tech-related channels, this is the first time YouTube recommended me to this channel.","author":"@chyldstudios","author_id":"UCoxgRBEk_fIKnlg_Qx8ughQ","like_count":396,"published_time":"2 years ago"},{"id":"Ugyt6Z4xGrMspdGvyKx4AaABAg","text":"Easily the greatest common divisor in the history of all common divisors","author":"@maisylover","author_id":"UCO_UB8B3SZ2M0uPZ0gp9aKQ","like_count":252,"published_time":"2 years ago"},{"id":"Ugx2A2jKZ5xI6NegQyl4AaABAg","text":"I was looking for something to snooze to and thought this was ASMR Assembly.","author":"@maelstrom57","author_id":"UC9BJqAqRlOJBAA0O4WYSmnw","like_count":77,"published_time":"2 years ago"},{"id":"UgxEwA0HYsWpnm94ol14AaABAg","text":"This is a great introduction and walk through for newcomers to assembly, but beware that the implementation has a quite significant flaw that will only reveal itself when called from other functions that have several live registers and happen to use r4 and store a value in it when it makes the call to this gcd function. The calling function will expect that the gcd function preserves the r4 register, as it is not a scratch register like r0-r3 are. This will manifest in miscalculations, unpredictable behavior and likely instability/crashes in the application using this function. An easy fix would be to push the r4 register along with lr to the stack, and pop it again (i.e. push {r4, lr} - pop {r4, pc}), but this of course increases the stack usage even more. Another approach would be to use r12 which is also a scratch register.\n\nIt would also be a good idea to make the implementation non-recursive as it can overflow the stack if it recurses too many times. For this algorithm this is quite easy as you can do tail call optimization by simply removing the push, replacing the pop by \"bx lr\" and doing a \"b gcd\" instead of \"bl gcd\" (which means the lr does not get overwritten for each iteration and retains the original return address that was written when the function was called the first time). This means the stack won't grow for each iteration.","author":"@ThomasThorsen","author_id":"UCrnn5DYsdOmhT13aXqqsUUg","like_count":97,"published_time":"2 years ago"},{"id":"UgwNKziAUmlG6AXRII14AaABAg","text":"praise the algorithm gods... how am i only just learning about this channel?","author":"@gcrannell","author_id":"UCpnZDR1AXRsYtMcDw35hQHw","like_count":48,"published_time":"2 years ago"},{"id":"UgydkMM5TmT0NWFIDOJ4AaABAg","text":"I finally watch Lain and now the Youtube algorithm is rewarding me","author":"@Summanis","author_id":"UC9hG-mlN6ktivoTLV7snN9Q","like_count":84,"published_time":"2 years ago"},{"id":"Ugz-7QdxrX4u307hjx14AaABAg","text":"I love the XP rice 😂","author":"@thejintent2770","author_id":"UCo_w3QOCgmvgW0bP6nyWlLw","like_count":10,"published_time":"2 years ago"},{"id":"UgzUmGw6JCivvaTQ6Ml4AaABAg","text":"Underrated channel. I cannot wait to get fat enough in my CS courses to understand this","author":"@mebibyte9347","author_id":"UCdhqpME4X4_bQB9Esg7pCtw","like_count":89,"published_time":"2 years ago"},{"id":"UgzbfKnwxE7CD2fZxQ54AaABAg","text":"The quality of the video and the content is top notch. Here before 1 M subscribers","author":"@ogphoenix8965","author_id":"UCo6f35f9M3xqAoGKM5OGwfg","like_count":20,"published_time":"2 years ago"},{"id":"UgxKy4C0T-wMsaqh_qp4AaABAg","text":"So it's been a few years since I was last writing in ARM asm (32-bit MCUs), so I might be a bit rusty... but I thought I saw a few tricks you'd missed, opened a notepad and downloaded an arm instruction-set reference and had a go myself. What I noticed:\n\n1: this is an ideal opportunity for tail recursion, simplifying the recursion to effectively a loop and removing the need to unwind the calls from the stack at the end\n2: move can set flags, removing the need to compare to determine zero both on entry and within the loop\n3: once you don't need to push/pop, bx lr can be used to return and can even be used with condition codes\n\n;; arm version\n\ngcd:\n\tmovs\tr1, r1\t\t;; mov can set flags? easiest way to get the z flag set for a zero input?\n\tbxeq\tlr\t\t\t;; conditional return. nice. assumes A32 instruction set tho...\n.loop:\n\tsdiv\t\tr2, r0, r1\t\t;; I find it surprising that ARM doesn't have some way to return\n\tmul\t\tr2, r2, r1\t\t;;  the remainder from a division... the bits are right there at the\n\tsub\t\tr2, r0, r2\t\t;;  end of the process, but then they get lost? and I have to recompute them? smh.\n\tmov\tr0, r1\t\t;; but even so, the ARM version is still smaller and neater than the x86,\n\tmovs\tr1, r2\t\t;;  which has to dance around the fixed register usage of its DIV instruction\n\tbne\t\tloop\t\t;; mov setting flags means that we can conditionally loop - also could set flags on the sub\n\tbx\t\tlr\t\t\t;; tail recursion means no push lr/pop pc, and we can use the direct return\n\n4: all this is very academic since most of the time will be in the div operation anyway...\n\n;; x86 version for comparison\n\ngcd:\t\t\t\t\t; expects a in edi, b in esi\n\tmov\teax, edi\n\ttest\t\tesi, esi\n\tjz\t\t.out\t\t\t;; no conditional return\n.loop:\n\txor\t\tedx, edx\t\t;; top half of dividand must be zeroed\n\tdiv\t\tesi\t\t\t;; div takes edx:eax as dividand, returns quotient in eax and remainder in edx\n\tmov\teax, esi\n\tmov\tesi, edx\n\ttest\t\tedx, edx\t\t;; have to use dedicated instruction for setting flags\n\tjnz\t\t.loop\t\t;; but at least these test/branch combo's get turned into a single µop when executed\n.out:\n\tret\t\t\t\t\t; return is in eax\n\n;;; the iterative logic as C\n\nint gcd(int a, int b) {\n\tif(!b) return a;\n\tint c;\n\twhile(c = a % b) { a = b; b = c; }\n\treturn b;\n}","author":"@treelibrarian7618","author_id":"UCFXKR8B0LqYQAGXNLWOuzBw","like_count":89,"published_time":"2 years ago"},{"id":"UgyKnvK90V3kgVl-wpd4AaABAg","text":"I don't know what the heckin flip I'm watching but I freakin know it's epic dude.","author":"@jonasc1221","author_id":"UC0-NCPzaT7XjGFdXAT4uXrA","like_count":1,"published_time":"2 years ago"},{"id":"UgwWLrufjJ5sbLDCkxF4AaABAg","text":"just in case, the modulo implementation works out if you use integer division not \"normal\" division\n(2//5)*5=0, but (2/5)*5=2","author":"@maydude2","author_id":"UCminbZdDmzr4QsUH1B5Fwyg","like_count":6,"published_time":"2 years ago"},{"id":"UgwEkRVspJzaseKBgLB4AaABAg","text":"Very nice walk-through! Small tip: if you ‘:set autoindent expandtab tabstop=8’, you can then use the <TAB> key to indent with spaces, and you will have a nicer vim experience.","author":"@edgarbonet1","author_id":"UC9KL7XU5j5HX-FbEJKJPtlg","like_count":1,"published_time":"11 months ago"},{"id":"UgxI0UdR8HAuTIewPzp4AaABAg","text":"looking for YouTuber making tutorial about arm assembly, never found, and tonight YouTube recommended this channel, okay YouTube, okay","author":"@hlodvic6678","author_id":"UCpvr8OL9OqXpkTIVp_y-Kxg","like_count":1,"published_time":"2 years ago"},{"id":"Ugw1I89X4X0aVw37Brp4AaABAg","text":"Everybody who comments \"the algorithm brought me here\" needs to immediately like and subscribe. Thats how we can boost channels like this","author":"@gcrannell","author_id":"UCpnZDR1AXRsYtMcDw35hQHw","like_count":1,"published_time":"2 years ago"},{"id":"UgyQ5xOf7YTmJLDvagR4AaABAg","text":"I have been watching tech and programming channels for many years. This is the first time YouTube has recommended you. Glad to see it!","author":"@PaulEmsley","author_id":"UCbHAnhn_6MOmmjMMhR_0qkQ","like_count":10,"published_time":"2 years ago"},{"id":"UgxQn1SKh8yO_ciQy_54AaABAg","text":"weird way to propose but yes I accept","author":"@eduardoignacioroblessosa6349","author_id":"UCSDgxJoiZWswDOpph8sGn9w","like_count":2,"published_time":"2 years ago"},{"id":"UgyDOiM-YIy5EaE6ouZ4AaABAg","text":"OMG. Last time I wrote assembly was like 20 years ago! I love this woman!","author":"@sushiConPorotos","author_id":"UC1V0DFx7BlfCI9xVKPgQsOA","like_count":10,"published_time":"2 years ago"},{"id":"UgyHWJWuOK-uTLDe3yF4AaABAg","text":"I last coded in Arm for an Acorn Archimedes about 35 years ago. Thanks for the memory jolt.","author":"@CrestRising","author_id":"UCWbsTFBqosZXS2J_P-j4XCQ","like_count":1,"published_time":"2 years ago"},{"id":"Ugzv0nPUexcaoURHiRF4AaABAg","text":"Serial Experiments Lain! And the Wired. Wow!!! 😳 Awesome references. Just stumbled on this channel, so I wanted to acknowledge that. 😊","author":"@traal","author_id":"UC8kVxpH5j7I_613bRZ_d5ig","like_count":32,"published_time":"2 years ago"},{"id":"UgyKSncBdPsNdD792dx4AaABAg","text":"As someone who subscribes to a ton of tech-related channels, this is the first time YouTube recommended me to this channel.","author":"@chyldstudios","author_id":"UCoxgRBEk_fIKnlg_Qx8ughQ","like_count":396,"published_time":"2 years ago"},{"id":"Ugyt6Z4xGrMspdGvyKx4AaABAg","text":"Easily the greatest common divisor in the history of all common divisors","author":"@maisylover","author_id":"UCO_UB8B3SZ2M0uPZ0gp9aKQ","like_count":252,"published_time":"2 years ago"},{"id":"Ugx2A2jKZ5xI6NegQyl4AaABAg","text":"I was looking for something to snooze to and thought this was ASMR Assembly.","author":"@maelstrom57","author_id":"UC9BJqAqRlOJBAA0O4WYSmnw","like_count":77,"published_time":"2 years ago"},{"id":"UgzbfKnwxE7CD2fZxQ54AaABAg","text":"The quality of the video and the content is top notch. Here before 1 M subscribers","author":"@ogphoenix8965","author_id":"UCo6f35f9M3xqAoGKM5OGwfg","like_count":20,"published_time":"2 years ago"},{"id":"UgwNKziAUmlG6AXRII14AaABAg","text":"praise the algorithm gods... how am i only just learning about this channel?","author":"@gcrannell","author_id":"UCpnZDR1AXRsYtMcDw35hQHw","like_count":48,"published_time":"2 years ago"},{"id":"UgydkMM5TmT0NWFIDOJ4AaABAg","text":"I finally watch Lain and now the Youtube algorithm is rewarding me","author":"@Summanis","author_id":"UC9hG-mlN6ktivoTLV7snN9Q","like_count":84,"published_time":"2 years ago"},{"id":"UgyQ5xOf7YTmJLDvagR4AaABAg","text":"I have been watching tech and programming channels for many years. This is the first time YouTube has recommended you. Glad to see it!","author":"@PaulEmsley","author_id":"UCbHAnhn_6MOmmjMMhR_0qkQ","like_count":10,"published_time":"2 years ago"},{"id":"UgwWLrufjJ5sbLDCkxF4AaABAg","text":"just in case, the modulo implementation works out if you use integer division not \"normal\" division\n(2//5)*5=0, but (2/5)*5=2","author":"@maydude2","author_id":"UCminbZdDmzr4QsUH1B5Fwyg","like_count":6,"published_time":"2 years ago"},{"id":"UgxI0UdR8HAuTIewPzp4AaABAg","text":"looking for YouTuber making tutorial about arm assembly, never found, and tonight YouTube recommended this channel, okay YouTube, okay","author":"@hlodvic6678","author_id":"UCpvr8OL9OqXpkTIVp_y-Kxg","like_count":1,"published_time":"2 years ago"},{"id":"UgxEwA0HYsWpnm94ol14AaABAg","text":"This is a great introduction and walk through for newcomers to assembly, but beware that the implementation has a quite significant flaw that will only reveal itself when called from other functions that have several live registers and happen to use r4 and store a value in it when it makes the call to this gcd function. The calling function will expect that the gcd function preserves the r4 register, as it is not a scratch register like r0-r3 are. This will manifest in miscalculations, unpredictable behavior and likely instability/crashes in the application using this function. An easy fix would be to push the r4 register along with lr to the stack, and pop it again (i.e. push {r4, lr} - pop {r4, pc}), but this of course increases the stack usage even more. Another approach would be to use r12 which is also a scratch register.\n\nIt would also be a good idea to make the implementation non-recursive as it can overflow the stack if it recurses too many times. For this algorithm this is quite easy as you can do tail call optimization by simply removing the push, replacing the pop by \"bx lr\" and doing a \"b gcd\" instead of \"bl gcd\" (which means the lr does not get overwritten for each iteration and retains the original return address that was written when the function was called the first time). This means the stack won't grow for each iteration.","author":"@ThomasThorsen","author_id":"UCrnn5DYsdOmhT13aXqqsUUg","like_count":97,"published_time":"2 years ago"},{"id":"Ugyfje5VGCaYkZjTujR4AaABAg","text":"I feel like Laurie must have a really cool dad","author":"@fignuuuts","author_id":"UC6JtSRDcxaUMfxvKbBz3hdQ","like_count":1,"published_time":"2 years ago"},{"id":"UgyKnvK90V3kgVl-wpd4AaABAg","text":"I don't know what the heckin flip I'm watching but I freakin know it's epic dude.","author":"@jonasc1221","author_id":"UC0-NCPzaT7XjGFdXAT4uXrA","like_count":1,"published_time":"2 years ago"},{"id":"UgwFY-PWCyogyUf_s6h4AaABAg","text":"I don't know, this just clicks every key, this atmosphere is perfect","author":"@cheleon94","author_id":"UCsj1bsS7_BkCqx57G48arnA","like_count":0,"published_time":"2 years ago"},{"id":"UgzUmGw6JCivvaTQ6Ml4AaABAg","text":"Underrated channel. I cannot wait to get fat enough in my CS courses to understand this","author":"@mebibyte9347","author_id":"UCdhqpME4X4_bQB9Esg7pCtw","like_count":89,"published_time":"2 years ago"},{"id":"UgyDOiM-YIy5EaE6ouZ4AaABAg","text":"OMG. Last time I wrote assembly was like 20 years ago! I love this woman!","author":"@sushiConPorotos","author_id":"UC1V0DFx7BlfCI9xVKPgQsOA","like_count":10,"published_time":"2 years ago"},{"id":"UgyHWJWuOK-uTLDe3yF4AaABAg","text":"I last coded in Arm for an Acorn Archimedes about 35 years ago. Thanks for the memory jolt.","author":"@CrestRising","author_id":"UCWbsTFBqosZXS2J_P-j4XCQ","like_count":1,"published_time":"2 years ago"},{"id":"Ugyyn9WT5ueQEI3AjrZ4AaABAg","text":"This video style gives me a lot of nostalgia","author":"@guardian-X","author_id":"UCFtHJk_l5cBD1Fj4pPWqF1A","like_count":1,"published_time":"2 years ago"},{"id":"UgwDwxKp4AEnr7K8HE54AaABAg","text":"I don't have the patience for coding but I geniunely enjoyed this","author":"@OfficialiGamer","author_id":"UCLUIXlXBfUhZqYrWzr_mCyA","like_count":0,"published_time":"2 years ago"},{"id":"Ugzv0nPUexcaoURHiRF4AaABAg","text":"Serial Experiments Lain! And the Wired. Wow!!! 😳 Awesome references. Just stumbled on this channel, so I wanted to acknowledge that. 😊","author":"@traal","author_id":"UC8kVxpH5j7I_613bRZ_d5ig","like_count":32,"published_time":"2 years ago"},{"id":"Ugw1I89X4X0aVw37Brp4AaABAg","text":"Everybody who comments \"the algorithm brought me here\" needs to immediately like and subscribe. Thats how we can boost channels like this","author":"@gcrannell","author_id":"UCpnZDR1AXRsYtMcDw35hQHw","like_count":1,"published_time":"2 years ago"},{"id":"Ugyt6Z4xGrMspdGvyKx4AaABAg","text":"Easily the greatest common divisor in the history of all common divisors","author":"@maisylover","author_id":"UCO_UB8B3SZ2M0uPZ0gp9aKQ","like_count":252,"published_time":"2 years ago"},{"id":"Ugx2A2jKZ5xI6NegQyl4AaABAg","text":"I was looking for something to snooze to and thought this was ASMR Assembly.","author":"@maelstrom57","author_id":"UC9BJqAqRlOJBAA0O4WYSmnw","like_count":77,"published_time":"2 years ago"},{"id":"UgyKSncBdPsNdD792dx4AaABAg","text":"As someone who subscribes to a ton of tech-related channels, this is the first time YouTube recommended me to this channel.","author":"@chyldstudios","author_id":"UCoxgRBEk_fIKnlg_Qx8ughQ","like_count":396,"published_time":"2 years ago"},{"id":"UgxEwA0HYsWpnm94ol14AaABAg","text":"This is a great introduction and walk through for newcomers to assembly, but beware that the implementation has a quite significant flaw that will only reveal itself when called from other functions that have several live registers and happen to use r4 and store a value in it when it makes the call to this gcd function. The calling function will expect that the gcd function preserves the r4 register, as it is not a scratch register like r0-r3 are. This will manifest in miscalculations, unpredictable behavior and likely instability/crashes in the application using this function. An easy fix would be to push the r4 register along with lr to the stack, and pop it again (i.e. push {r4, lr} - pop {r4, pc}), but this of course increases the stack usage even more. Another approach would be to use r12 which is also a scratch register.\n\nIt would also be a good idea to make the implementation non-recursive as it can overflow the stack if it recurses too many times. For this algorithm this is quite easy as you can do tail call optimization by simply removing the push, replacing the pop by \"bx lr\" and doing a \"b gcd\" instead of \"bl gcd\" (which means the lr does not get overwritten for each iteration and retains the original return address that was written when the function was called the first time). This means the stack won't grow for each iteration.","author":"@ThomasThorsen","author_id":"UCrnn5DYsdOmhT13aXqqsUUg","like_count":97,"published_time":"2 years ago"},{"id":"UgzbfKnwxE7CD2fZxQ54AaABAg","text":"The quality of the video and the content is top notch. Here before 1 M subscribers","author":"@ogphoenix8965","author_id":"UCo6f35f9M3xqAoGKM5OGwfg","like_count":20,"published_time":"2 years ago"},{"id":"UgzUmGw6JCivvaTQ6Ml4AaABAg","text":"Underrated channel. I cannot wait to get fat enough in my CS courses to understand this","author":"@mebibyte9347","author_id":"UCdhqpME4X4_bQB9Esg7pCtw","like_count":89,"published_time":"2 years ago"},{"id":"UgydkMM5TmT0NWFIDOJ4AaABAg","text":"I finally watch Lain and now the Youtube algorithm is rewarding me","author":"@Summanis","author_id":"UC9hG-mlN6ktivoTLV7snN9Q","like_count":84,"published_time":"2 years ago"},{"id":"Ugz-7QdxrX4u307hjx14AaABAg","text":"I love the XP rice 😂","author":"@thejintent2770","author_id":"UCo_w3QOCgmvgW0bP6nyWlLw","like_count":10,"published_time":"2 years ago"},{"id":"UgxKy4C0T-wMsaqh_qp4AaABAg","text":"So it's been a few years since I was last writing in ARM asm (32-bit MCUs), so I might be a bit rusty... but I thought I saw a few tricks you'd missed, opened a notepad and downloaded an arm instruction-set reference and had a go myself. What I noticed:\n\n1: this is an ideal opportunity for tail recursion, simplifying the recursion to effectively a loop and removing the need to unwind the calls from the stack at the end\n2: move can set flags, removing the need to compare to determine zero both on entry and within the loop\n3: once you don't need to push/pop, bx lr can be used to return and can even be used with condition codes\n\n;; arm version\n\ngcd:\n\tmovs\tr1, r1\t\t;; mov can set flags? easiest way to get the z flag set for a zero input?\n\tbxeq\tlr\t\t\t;; conditional return. nice. assumes A32 instruction set tho...\n.loop:\n\tsdiv\t\tr2, r0, r1\t\t;; I find it surprising that ARM doesn't have some way to return\n\tmul\t\tr2, r2, r1\t\t;;  the remainder from a division... the bits are right there at the\n\tsub\t\tr2, r0, r2\t\t;;  end of the process, but then they get lost? and I have to recompute them? smh.\n\tmov\tr0, r1\t\t;; but even so, the ARM version is still smaller and neater than the x86,\n\tmovs\tr1, r2\t\t;;  which has to dance around the fixed register usage of its DIV instruction\n\tbne\t\tloop\t\t;; mov setting flags means that we can conditionally loop - also could set flags on the sub\n\tbx\t\tlr\t\t\t;; tail recursion means no push lr/pop pc, and we can use the direct return\n\n4: all this is very academic since most of the time will be in the div operation anyway...\n\n;; x86 version for comparison\n\ngcd:\t\t\t\t\t; expects a in edi, b in esi\n\tmov\teax, edi\n\ttest\t\tesi, esi\n\tjz\t\t.out\t\t\t;; no conditional return\n.loop:\n\txor\t\tedx, edx\t\t;; top half of dividand must be zeroed\n\tdiv\t\tesi\t\t\t;; div takes edx:eax as dividand, returns quotient in eax and remainder in edx\n\tmov\teax, esi\n\tmov\tesi, edx\n\ttest\t\tedx, edx\t\t;; have to use dedicated instruction for setting flags\n\tjnz\t\t.loop\t\t;; but at least these test/branch combo's get turned into a single µop when executed\n.out:\n\tret\t\t\t\t\t; return is in eax\n\n;;; the iterative logic as C\n\nint gcd(int a, int b) {\n\tif(!b) return a;\n\tint c;\n\twhile(c = a % b) { a = b; b = c; }\n\treturn b;\n}","author":"@treelibrarian7618","author_id":"UCFXKR8B0LqYQAGXNLWOuzBw","like_count":89,"published_time":"2 years ago"},{"id":"UgyKnvK90V3kgVl-wpd4AaABAg","text":"I don't know what the heckin flip I'm watching but I freakin know it's epic dude.","author":"@jonasc1221","author_id":"UC0-NCPzaT7XjGFdXAT4uXrA","like_count":1,"published_time":"2 years ago"},{"id":"UgyQ5xOf7YTmJLDvagR4AaABAg","text":"I have been watching tech and programming channels for many years. This is the first time YouTube has recommended you. Glad to see it!","author":"@PaulEmsley","author_id":"UCbHAnhn_6MOmmjMMhR_0qkQ","like_count":10,"published_time":"2 years ago"},{"id":"UgwEkRVspJzaseKBgLB4AaABAg","text":"Very nice walk-through! Small tip: if you ‘:set autoindent expandtab tabstop=8’, you can then use the <TAB> key to indent with spaces, and you will have a nicer vim experience.","author":"@edgarbonet1","author_id":"UC9KL7XU5j5HX-FbEJKJPtlg","like_count":1,"published_time":"11 months ago"},{"id":"UgwWLrufjJ5sbLDCkxF4AaABAg","text":"just in case, the modulo implementation works out if you use integer division not \"normal\" division\n(2//5)*5=0, but (2/5)*5=2","author":"@maydude2","author_id":"UCminbZdDmzr4QsUH1B5Fwyg","like_count":6,"published_time":"2 years ago"},{"id":"UgwNKziAUmlG6AXRII14AaABAg","text":"praise the algorithm gods... how am i only just learning about this channel?","author":"@gcrannell","author_id":"UCpnZDR1AXRsYtMcDw35hQHw","like_count":48,"published_time":"2 years ago"},{"id":"Ugzv0nPUexcaoURHiRF4AaABAg","text":"Serial Experiments Lain! And the Wired. Wow!!! 😳 Awesome references. Just stumbled on this channel, so I wanted to acknowledge that. 😊","author":"@traal","author_id":"UC8kVxpH5j7I_613bRZ_d5ig","like_count":32,"published_time":"2 years ago"},{"id":"UgxI0UdR8HAuTIewPzp4AaABAg","text":"looking for YouTuber making tutorial about arm assembly, never found, and tonight YouTube recommended this channel, okay YouTube, okay","author":"@hlodvic6678","author_id":"UCpvr8OL9OqXpkTIVp_y-Kxg","like_count":1,"published_time":"2 years ago"},{"id":"UgyHWJWuOK-uTLDe3yF4AaABAg","text":"I last coded in Arm for an Acorn Archimedes about 35 years ago. Thanks for the memory jolt.","author":"@CrestRising","author_id":"UCWbsTFBqosZXS2J_P-j4XCQ","like_count":1,"published_time":"2 years ago"},{"id":"UgzOsgsAOIN8I-4pfeZ4AaABAg","text":"Same!\n\nThis is the most ideal content for me possible and her channel has never once come up in recommendations or relevant search\n\nLike, this is making me question if the YouTube algorithm is even remotely effective in a meaningful way, I only found her channel because I tried the new(ish) “explore outside your recommendations” feature they’ve started pushing.","author":"@iamtheblurr","author_id":"UC6s3KTgsMKUH8tQRvhnwxkg","like_count":1,"published_time":"2 years ago"},{"id":"UgziwFQUJ04m47nHirV4AaABAg","text":"love ur XP theme :D brings back memories","author":"@so7am96","author_id":"UCAQtT6vVDvRRTHcAUcRCz5g","like_count":4,"published_time":"2 years ago"},{"id":"UgzzWv9xhmiQ5fvPHR14AaABAg","text":"Haven't done any coding since 1985-86.  But somehow your video popped up in my feed...  I did enjoy the video!","author":"@clarkgriswold-zr5sb","author_id":"UCAwsFvTLtop54dBGTDDUhVg","like_count":2,"published_time":"2 years ago (edited)"},{"id":"UgyKSncBdPsNdD792dx4AaABAg","text":"As someone who subscribes to a ton of tech-related channels, this is the first time YouTube recommended me to this channel.","author":"@chyldstudios","author_id":"UCoxgRBEk_fIKnlg_Qx8ughQ","like_count":396,"published_time":"2 years ago"},{"id":"Ugyt6Z4xGrMspdGvyKx4AaABAg","text":"Easily the greatest common divisor in the history of all common divisors","author":"@maisylover","author_id":"UCO_UB8B3SZ2M0uPZ0gp9aKQ","like_count":252,"published_time":"2 years ago"},{"id":"Ugx2A2jKZ5xI6NegQyl4AaABAg","text":"I was looking for something to snooze to and thought this was ASMR Assembly.","author":"@maelstrom57","author_id":"UC9BJqAqRlOJBAA0O4WYSmnw","like_count":77,"published_time":"2 years ago"},{"id":"UgxEwA0HYsWpnm94ol14AaABAg","text":"This is a great introduction and walk through for newcomers to assembly, but beware that the implementation has a quite significant flaw that will only reveal itself when called from other functions that have several live registers and happen to use r4 and store a value in it when it makes the call to this gcd function. The calling function will expect that the gcd function preserves the r4 register, as it is not a scratch register like r0-r3 are. This will manifest in miscalculations, unpredictable behavior and likely instability/crashes in the application using this function. An easy fix would be to push the r4 register along with lr to the stack, and pop it again (i.e. push {r4, lr} - pop {r4, pc}), but this of course increases the stack usage even more. Another approach would be to use r12 which is also a scratch register.\n\nIt would also be a good idea to make the implementation non-recursive as it can overflow the stack if it recurses too many times. For this algorithm this is quite easy as you can do tail call optimization by simply removing the push, replacing the pop by \"bx lr\" and doing a \"b gcd\" instead of \"bl gcd\" (which means the lr does not get overwritten for each iteration and retains the original return address that was written when the function was called the first time). This means the stack won't grow for each iteration.","author":"@ThomasThorsen","author_id":"UCrnn5DYsdOmhT13aXqqsUUg","like_count":97,"published_time":"2 years ago"},{"id":"UgwNKziAUmlG6AXRII14AaABAg","text":"praise the algorithm gods... how am i only just learning about this channel?","author":"@gcrannell","author_id":"UCpnZDR1AXRsYtMcDw35hQHw","like_count":48,"published_time":"2 years ago"},{"id":"UgydkMM5TmT0NWFIDOJ4AaABAg","text":"I finally watch Lain and now the Youtube algorithm is rewarding me","author":"@Summanis","author_id":"UC9hG-mlN6ktivoTLV7snN9Q","like_count":84,"published_time":"2 years ago"},{"id":"Ugz-7QdxrX4u307hjx14AaABAg","text":"I love the XP rice 😂","author":"@thejintent2770","author_id":"UCo_w3QOCgmvgW0bP6nyWlLw","like_count":10,"published_time":"2 years ago"},{"id":"UgzUmGw6JCivvaTQ6Ml4AaABAg","text":"Underrated channel. I cannot wait to get fat enough in my CS courses to understand this","author":"@mebibyte9347","author_id":"UCdhqpME4X4_bQB9Esg7pCtw","like_count":89,"published_time":"2 years ago"},{"id":"UgzbfKnwxE7CD2fZxQ54AaABAg","text":"The quality of the video and the content is top notch. Here before 1 M subscribers","author":"@ogphoenix8965","author_id":"UCo6f35f9M3xqAoGKM5OGwfg","like_count":20,"published_time":"2 years ago"},{"id":"UgxKy4C0T-wMsaqh_qp4AaABAg","text":"So it's been a few years since I was last writing in ARM asm (32-bit MCUs), so I might be a bit rusty... but I thought I saw a few tricks you'd missed, opened a notepad and downloaded an arm instruction-set reference and had a go myself. What I noticed:\n\n1: this is an ideal opportunity for tail recursion, simplifying the recursion to effectively a loop and removing the need to unwind the calls from the stack at the end\n2: move can set flags, removing the need to compare to determine zero both on entry and within the loop\n3: once you don't need to push/pop, bx lr can be used to return and can even be used with condition codes\n\n;; arm version\n\ngcd:\n\tmovs\tr1, r1\t\t;; mov can set flags? easiest way to get the z flag set for a zero input?\n\tbxeq\tlr\t\t\t;; conditional return. nice. assumes A32 instruction set tho...\n.loop:\n\tsdiv\t\tr2, r0, r1\t\t;; I find it surprising that ARM doesn't have some way to return\n\tmul\t\tr2, r2, r1\t\t;;  the remainder from a division... the bits are right there at the\n\tsub\t\tr2, r0, r2\t\t;;  end of the process, but then they get lost? and I have to recompute them? smh.\n\tmov\tr0, r1\t\t;; but even so, the ARM version is still smaller and neater than the x86,\n\tmovs\tr1, r2\t\t;;  which has to dance around the fixed register usage of its DIV instruction\n\tbne\t\tloop\t\t;; mov setting flags means that we can conditionally loop - also could set flags on the sub\n\tbx\t\tlr\t\t\t;; tail recursion means no push lr/pop pc, and we can use the direct return\n\n4: all this is very academic since most of the time will be in the div operation anyway...\n\n;; x86 version for comparison\n\ngcd:\t\t\t\t\t; expects a in edi, b in esi\n\tmov\teax, edi\n\ttest\t\tesi, esi\n\tjz\t\t.out\t\t\t;; no conditional return\n.loop:\n\txor\t\tedx, edx\t\t;; top half of dividand must be zeroed\n\tdiv\t\tesi\t\t\t;; div takes edx:eax as dividand, returns quotient in eax and remainder in edx\n\tmov\teax, esi\n\tmov\tesi, edx\n\ttest\t\tedx, edx\t\t;; have to use dedicated instruction for setting flags\n\tjnz\t\t.loop\t\t;; but at least these test/branch combo's get turned into a single µop when executed\n.out:\n\tret\t\t\t\t\t; return is in eax\n\n;;; the iterative logic as C\n\nint gcd(int a, int b) {\n\tif(!b) return a;\n\tint c;\n\twhile(c = a % b) { a = b; b = c; }\n\treturn b;\n}","author":"@treelibrarian7618","author_id":"UCFXKR8B0LqYQAGXNLWOuzBw","like_count":89,"published_time":"2 years ago"},{"id":"UgyKnvK90V3kgVl-wpd4AaABAg","text":"I don't know what the heckin flip I'm watching but I freakin know it's epic dude.","author":"@jonasc1221","author_id":"UC0-NCPzaT7XjGFdXAT4uXrA","like_count":1,"published_time":"2 years ago"},{"id":"UgwWLrufjJ5sbLDCkxF4AaABAg","text":"just in case, the modulo implementation works out if you use integer division not \"normal\" division\n(2//5)*5=0, but (2/5)*5=2","author":"@maydude2","author_id":"UCminbZdDmzr4QsUH1B5Fwyg","like_count":6,"published_time":"2 years ago"},{"id":"UgwEkRVspJzaseKBgLB4AaABAg","text":"Very nice walk-through! Small tip: if you ‘:set autoindent expandtab tabstop=8’, you can then use the <TAB> key to indent with spaces, and you will have a nicer vim experience.","author":"@edgarbonet1","author_id":"UC9KL7XU5j5HX-FbEJKJPtlg","like_count":1,"published_time":"11 months ago"},{"id":"UgxI0UdR8HAuTIewPzp4AaABAg","text":"looking for YouTuber making tutorial about arm assembly, never found, and tonight YouTube recommended this channel, okay YouTube, okay","author":"@hlodvic6678","author_id":"UCpvr8OL9OqXpkTIVp_y-Kxg","like_count":1,"published_time":"2 years ago"},{"id":"Ugw1I89X4X0aVw37Brp4AaABAg","text":"Everybody who comments \"the algorithm brought me here\" needs to immediately like and subscribe. Thats how we can boost channels like this","author":"@gcrannell","author_id":"UCpnZDR1AXRsYtMcDw35hQHw","like_count":1,"published_time":"2 years ago"},{"id":"UgyQ5xOf7YTmJLDvagR4AaABAg","text":"I have been watching tech and programming channels for many years. This is the first time YouTube has recommended you. Glad to see it!","author":"@PaulEmsley","author_id":"UCbHAnhn_6MOmmjMMhR_0qkQ","like_count":10,"published_time":"2 years ago"},{"id":"UgxQn1SKh8yO_ciQy_54AaABAg","text":"weird way to propose but yes I accept","author":"@eduardoignacioroblessosa6349","author_id":"UCSDgxJoiZWswDOpph8sGn9w","like_count":2,"published_time":"2 years ago"},{"id":"UgyDOiM-YIy5EaE6ouZ4AaABAg","text":"OMG. Last time I wrote assembly was like 20 years ago! I love this woman!","author":"@sushiConPorotos","author_id":"UC1V0DFx7BlfCI9xVKPgQsOA","like_count":10,"published_time":"2 years ago"},{"id":"UgyHWJWuOK-uTLDe3yF4AaABAg","text":"I last coded in Arm for an Acorn Archimedes about 35 years ago. Thanks for the memory jolt.","author":"@CrestRising","author_id":"UCWbsTFBqosZXS2J_P-j4XCQ","like_count":1,"published_time":"2 years ago"},{"id":"Ugzv0nPUexcaoURHiRF4AaABAg","text":"Serial Experiments Lain! And the Wired. Wow!!! 😳 Awesome references. Just stumbled on this channel, so I wanted to acknowledge that. 😊","author":"@traal","author_id":"UC8kVxpH5j7I_613bRZ_d5ig","like_count":32,"published_time":"2 years ago"},{"id":"UgyKSncBdPsNdD792dx4AaABAg","text":"As someone who subscribes to a ton of tech-related channels, this is the first time YouTube recommended me to this channel.","author":"@chyldstudios","author_id":"UCoxgRBEk_fIKnlg_Qx8ughQ","like_count":396,"published_time":"2 years ago"},{"id":"Ugyt6Z4xGrMspdGvyKx4AaABAg","text":"Easily the greatest common divisor in the history of all common divisors","author":"@maisylover","author_id":"UCO_UB8B3SZ2M0uPZ0gp9aKQ","like_count":252,"published_time":"2 years ago"},{"id":"Ugx2A2jKZ5xI6NegQyl4AaABAg","text":"I was looking for something to snooze to and thought this was ASMR Assembly.","author":"@maelstrom57","author_id":"UC9BJqAqRlOJBAA0O4WYSmnw","like_count":77,"published_time":"2 years ago"},{"id":"UgxEwA0HYsWpnm94ol14AaABAg","text":"This is a great introduction and walk through for newcomers to assembly, but beware that the implementation has a quite significant flaw that will only reveal itself when called from other functions that have several live registers and happen to use r4 and store a value in it when it makes the call to this gcd function. The calling function will expect that the gcd function preserves the r4 register, as it is not a scratch register like r0-r3 are. This will manifest in miscalculations, unpredictable behavior and likely instability/crashes in the application using this function. An easy fix would be to push the r4 register along with lr to the stack, and pop it again (i.e. push {r4, lr} - pop {r4, pc}), but this of course increases the stack usage even more. Another approach would be to use r12 which is also a scratch register.\n\nIt would also be a good idea to make the implementation non-recursive as it can overflow the stack if it recurses too many times. For this algorithm this is quite easy as you can do tail call optimization by simply removing the push, replacing the pop by \"bx lr\" and doing a \"b gcd\" instead of \"bl gcd\" (which means the lr does not get overwritten for each iteration and retains the original return address that was written when the function was called the first time). This means the stack won't grow for each iteration.","author":"@ThomasThorsen","author_id":"UCrnn5DYsdOmhT13aXqqsUUg","like_count":97,"published_time":"2 years ago"},{"id":"UgwNKziAUmlG6AXRII14AaABAg","text":"praise the algorithm gods... how am i only just learning about this channel?","author":"@gcrannell","author_id":"UCpnZDR1AXRsYtMcDw35hQHw","like_count":48,"published_time":"2 years ago"},{"id":"UgydkMM5TmT0NWFIDOJ4AaABAg","text":"I finally watch Lain and now the Youtube algorithm is rewarding me","author":"@Summanis","author_id":"UC9hG-mlN6ktivoTLV7snN9Q","like_count":84,"published_time":"2 years ago"},{"id":"Ugz-7QdxrX4u307hjx14AaABAg","text":"I love the XP rice 😂","author":"@thejintent2770","author_id":"UCo_w3QOCgmvgW0bP6nyWlLw","like_count":10,"published_time":"2 years ago"},{"id":"UgzUmGw6JCivvaTQ6Ml4AaABAg","text":"Underrated channel. I cannot wait to get fat enough in my CS courses to understand this","author":"@mebibyte9347","author_id":"UCdhqpME4X4_bQB9Esg7pCtw","like_count":89,"published_time":"2 years ago"},{"id":"UgzbfKnwxE7CD2fZxQ54AaABAg","text":"The quality of the video and the content is top notch. Here before 1 M subscribers","author":"@ogphoenix8965","author_id":"UCo6f35f9M3xqAoGKM5OGwfg","like_count":20,"published_time":"2 years ago"},{"id":"UgxKy4C0T-wMsaqh_qp4AaABAg","text":"So it's been a few years since I was last writing in ARM asm (32-bit MCUs), so I might be a bit rusty... but I thought I saw a few tricks you'd missed, opened a notepad and downloaded an arm instruction-set reference and had a go myself. What I noticed:\n\n1: this is an ideal opportunity for tail recursion, simplifying the recursion to effectively a loop and removing the need to unwind the calls from the stack at the end\n2: move can set flags, removing the need to compare to determine zero both on entry and within the loop\n3: once you don't need to push/pop, bx lr can be used to return and can even be used with condition codes\n\n;; arm version\n\ngcd:\n\tmovs\tr1, r1\t\t;; mov can set flags? easiest way to get the z flag set for a zero input?\n\tbxeq\tlr\t\t\t;; conditional return. nice. assumes A32 instruction set tho...\n.loop:\n\tsdiv\t\tr2, r0, r1\t\t;; I find it surprising that ARM doesn't have some way to return\n\tmul\t\tr2, r2, r1\t\t;;  the remainder from a division... the bits are right there at the\n\tsub\t\tr2, r0, r2\t\t;;  end of the process, but then they get lost? and I have to recompute them? smh.\n\tmov\tr0, r1\t\t;; but even so, the ARM version is still smaller and neater than the x86,\n\tmovs\tr1, r2\t\t;;  which has to dance around the fixed register usage of its DIV instruction\n\tbne\t\tloop\t\t;; mov setting flags means that we can conditionally loop - also could set flags on the sub\n\tbx\t\tlr\t\t\t;; tail recursion means no push lr/pop pc, and we can use the direct return\n\n4: all this is very academic since most of the time will be in the div operation anyway...\n\n;; x86 version for comparison\n\ngcd:\t\t\t\t\t; expects a in edi, b in esi\n\tmov\teax, edi\n\ttest\t\tesi, esi\n\tjz\t\t.out\t\t\t;; no conditional return\n.loop:\n\txor\t\tedx, edx\t\t;; top half of dividand must be zeroed\n\tdiv\t\tesi\t\t\t;; div takes edx:eax as dividand, returns quotient in eax and remainder in edx\n\tmov\teax, esi\n\tmov\tesi, edx\n\ttest\t\tedx, edx\t\t;; have to use dedicated instruction for setting flags\n\tjnz\t\t.loop\t\t;; but at least these test/branch combo's get turned into a single µop when executed\n.out:\n\tret\t\t\t\t\t; return is in eax\n\n;;; the iterative logic as C\n\nint gcd(int a, int b) {\n\tif(!b) return a;\n\tint c;\n\twhile(c = a % b) { a = b; b = c; }\n\treturn b;\n}","author":"@treelibrarian7618","author_id":"UCFXKR8B0LqYQAGXNLWOuzBw","like_count":89,"published_time":"2 years ago"},{"id":"UgyKnvK90V3kgVl-wpd4AaABAg","text":"I don't know what the heckin flip I'm watching but I freakin know it's epic dude.","author":"@jonasc1221","author_id":"UC0-NCPzaT7XjGFdXAT4uXrA","like_count":1,"published_time":"2 years ago"},{"id":"UgwWLrufjJ5sbLDCkxF4AaABAg","text":"just in case, the modulo implementation works out if you use integer division not \"normal\" division\n(2//5)*5=0, but (2/5)*5=2","author":"@maydude2","author_id":"UCminbZdDmzr4QsUH1B5Fwyg","like_count":6,"published_time":"2 years ago"},{"id":"UgwEkRVspJzaseKBgLB4AaABAg","text":"Very nice walk-through! Small tip: if you ‘:set autoindent expandtab tabstop=8’, you can then use the <TAB> key to indent with spaces, and you will have a nicer vim experience.","author":"@edgarbonet1","author_id":"UC9KL7XU5j5HX-FbEJKJPtlg","like_count":1,"published_time":"11 months ago"},{"id":"UgxI0UdR8HAuTIewPzp4AaABAg","text":"looking for YouTuber making tutorial about arm assembly, never found, and tonight YouTube recommended this channel, okay YouTube, okay","author":"@hlodvic6678","author_id":"UCpvr8OL9OqXpkTIVp_y-Kxg","like_count":1,"published_time":"2 years ago"},{"id":"Ugw1I89X4X0aVw37Brp4AaABAg","text":"Everybody who comments \"the algorithm brought me here\" needs to immediately like and subscribe. Thats how we can boost channels like this","author":"@gcrannell","author_id":"UCpnZDR1AXRsYtMcDw35hQHw","like_count":1,"published_time":"2 years ago"},{"id":"UgyQ5xOf7YTmJLDvagR4AaABAg","text":"I have been watching tech and programming channels for many years. This is the first time YouTube has recommended you. Glad to see it!","author":"@PaulEmsley","author_id":"UCbHAnhn_6MOmmjMMhR_0qkQ","like_count":10,"published_time":"2 years ago"},{"id":"UgxQn1SKh8yO_ciQy_54AaABAg","text":"weird way to propose but yes I accept","author":"@eduardoignacioroblessosa6349","author_id":"UCSDgxJoiZWswDOpph8sGn9w","like_count":2,"published_time":"2 years ago"},{"id":"UgyDOiM-YIy5EaE6ouZ4AaABAg","text":"OMG. Last time I wrote assembly was like 20 years ago! I love this woman!","author":"@sushiConPorotos","author_id":"UC1V0DFx7BlfCI9xVKPgQsOA","like_count":10,"published_time":"2 years ago"},{"id":"UgyHWJWuOK-uTLDe3yF4AaABAg","text":"I last coded in Arm for an Acorn Archimedes about 35 years ago. Thanks for the memory jolt.","author":"@CrestRising","author_id":"UCWbsTFBqosZXS2J_P-j4XCQ","like_count":1,"published_time":"2 years ago"},{"id":"Ugzv0nPUexcaoURHiRF4AaABAg","text":"Serial Experiments Lain! And the Wired. Wow!!! 😳 Awesome references. Just stumbled on this channel, so I wanted to acknowledge that. 😊","author":"@traal","author_id":"UC8kVxpH5j7I_613bRZ_d5ig","like_count":32,"published_time":"2 years ago"},{"id":"UgyKSncBdPsNdD792dx4AaABAg","text":"As someone who subscribes to a ton of tech-related channels, this is the first time YouTube recommended me to this channel.","author":"@chyldstudios","author_id":"UCoxgRBEk_fIKnlg_Qx8ughQ","like_count":396,"published_time":"2 years ago"},{"id":"Ugyt6Z4xGrMspdGvyKx4AaABAg","text":"Easily the greatest common divisor in the history of all common divisors","author":"@maisylover","author_id":"UCO_UB8B3SZ2M0uPZ0gp9aKQ","like_count":252,"published_time":"2 years ago"},{"id":"Ugx2A2jKZ5xI6NegQyl4AaABAg","text":"I was looking for something to snooze to and thought this was ASMR Assembly.","author":"@maelstrom57","author_id":"UC9BJqAqRlOJBAA0O4WYSmnw","like_count":77,"published_time":"2 years ago"},{"id":"UgxEwA0HYsWpnm94ol14AaABAg","text":"This is a great introduction and walk through for newcomers to assembly, but beware that the implementation has a quite significant flaw that will only reveal itself when called from other functions that have several live registers and happen to use r4 and store a value in it when it makes the call to this gcd function. The calling function will expect that the gcd function preserves the r4 register, as it is not a scratch register like r0-r3 are. This will manifest in miscalculations, unpredictable behavior and likely instability/crashes in the application using this function. An easy fix would be to push the r4 register along with lr to the stack, and pop it again (i.e. push {r4, lr} - pop {r4, pc}), but this of course increases the stack usage even more. Another approach would be to use r12 which is also a scratch register.\n\nIt would also be a good idea to make the implementation non-recursive as it can overflow the stack if it recurses too many times. For this algorithm this is quite easy as you can do tail call optimization by simply removing the push, replacing the pop by \"bx lr\" and doing a \"b gcd\" instead of \"bl gcd\" (which means the lr does not get overwritten for each iteration and retains the original return address that was written when the function was called the first time). This means the stack won't grow for each iteration.","author":"@ThomasThorsen","author_id":"UCrnn5DYsdOmhT13aXqqsUUg","like_count":97,"published_time":"2 years ago"},{"id":"UgwNKziAUmlG6AXRII14AaABAg","text":"praise the algorithm gods... how am i only just learning about this channel?","author":"@gcrannell","author_id":"UCpnZDR1AXRsYtMcDw35hQHw","like_count":48,"published_time":"2 years ago"},{"id":"UgydkMM5TmT0NWFIDOJ4AaABAg","text":"I finally watch Lain and now the Youtube algorithm is rewarding me","author":"@Summanis","author_id":"UC9hG-mlN6ktivoTLV7snN9Q","like_count":84,"published_time":"2 years ago"},{"id":"Ugz-7QdxrX4u307hjx14AaABAg","text":"I love the XP rice 😂","author":"@thejintent2770","author_id":"UCo_w3QOCgmvgW0bP6nyWlLw","like_count":10,"published_time":"2 years ago"},{"id":"UgzUmGw6JCivvaTQ6Ml4AaABAg","text":"Underrated channel. I cannot wait to get fat enough in my CS courses to understand this","author":"@mebibyte9347","author_id":"UCdhqpME4X4_bQB9Esg7pCtw","like_count":89,"published_time":"2 years ago"},{"id":"UgzbfKnwxE7CD2fZxQ54AaABAg","text":"The quality of the video and the content is top notch. Here before 1 M subscribers","author":"@ogphoenix8965","author_id":"UCo6f35f9M3xqAoGKM5OGwfg","like_count":20,"published_time":"2 years ago"},{"id":"UgxKy4C0T-wMsaqh_qp4AaABAg","text":"So it's been a few years since I was last writing in ARM asm (32-bit MCUs), so I might be a bit rusty... but I thought I saw a few tricks you'd missed, opened a notepad and downloaded an arm instruction-set reference and had a go myself. What I noticed:\n\n1: this is an ideal opportunity for tail recursion, simplifying the recursion to effectively a loop and removing the need to unwind the calls from the stack at the end\n2: move can set flags, removing the need to compare to determine zero both on entry and within the loop\n3: once you don't need to push/pop, bx lr can be used to return and can even be used with condition codes\n\n;; arm version\n\ngcd:\n\tmovs\tr1, r1\t\t;; mov can set flags? easiest way to get the z flag set for a zero input?\n\tbxeq\tlr\t\t\t;; conditional return. nice. assumes A32 instruction set tho...\n.loop:\n\tsdiv\t\tr2, r0, r1\t\t;; I find it surprising that ARM doesn't have some way to return\n\tmul\t\tr2, r2, r1\t\t;;  the remainder from a division... the bits are right there at the\n\tsub\t\tr2, r0, r2\t\t;;  end of the process, but then they get lost? and I have to recompute them? smh.\n\tmov\tr0, r1\t\t;; but even so, the ARM version is still smaller and neater than the x86,\n\tmovs\tr1, r2\t\t;;  which has to dance around the fixed register usage of its DIV instruction\n\tbne\t\tloop\t\t;; mov setting flags means that we can conditionally loop - also could set flags on the sub\n\tbx\t\tlr\t\t\t;; tail recursion means no push lr/pop pc, and we can use the direct return\n\n4: all this is very academic since most of the time will be in the div operation anyway...\n\n;; x86 version for comparison\n\ngcd:\t\t\t\t\t; expects a in edi, b in esi\n\tmov\teax, edi\n\ttest\t\tesi, esi\n\tjz\t\t.out\t\t\t;; no conditional return\n.loop:\n\txor\t\tedx, edx\t\t;; top half of dividand must be zeroed\n\tdiv\t\tesi\t\t\t;; div takes edx:eax as dividand, returns quotient in eax and remainder in edx\n\tmov\teax, esi\n\tmov\tesi, edx\n\ttest\t\tedx, edx\t\t;; have to use dedicated instruction for setting flags\n\tjnz\t\t.loop\t\t;; but at least these test/branch combo's get turned into a single µop when executed\n.out:\n\tret\t\t\t\t\t; return is in eax\n\n;;; the iterative logic as C\n\nint gcd(int a, int b) {\n\tif(!b) return a;\n\tint c;\n\twhile(c = a % b) { a = b; b = c; }\n\treturn b;\n}","author":"@treelibrarian7618","author_id":"UCFXKR8B0LqYQAGXNLWOuzBw","like_count":89,"published_time":"2 years ago"},{"id":"UgyKnvK90V3kgVl-wpd4AaABAg","text":"I don't know what the heckin flip I'm watching but I freakin know it's epic dude.","author":"@jonasc1221","author_id":"UC0-NCPzaT7XjGFdXAT4uXrA","like_count":1,"published_time":"2 years ago"},{"id":"UgwWLrufjJ5sbLDCkxF4AaABAg","text":"just in case, the modulo implementation works out if you use integer division not \"normal\" division\n(2//5)*5=0, but (2/5)*5=2","author":"@maydude2","author_id":"UCminbZdDmzr4QsUH1B5Fwyg","like_count":6,"published_time":"2 years ago"},{"id":"UgwEkRVspJzaseKBgLB4AaABAg","text":"Very nice walk-through! Small tip: if you ‘:set autoindent expandtab tabstop=8’, you can then use the <TAB> key to indent with spaces, and you will have a nicer vim experience.","author":"@edgarbonet1","author_id":"UC9KL7XU5j5HX-FbEJKJPtlg","like_count":1,"published_time":"11 months ago"},{"id":"UgxI0UdR8HAuTIewPzp4AaABAg","text":"looking for YouTuber making tutorial about arm assembly, never found, and tonight YouTube recommended this channel, okay YouTube, okay","author":"@hlodvic6678","author_id":"UCpvr8OL9OqXpkTIVp_y-Kxg","like_count":1,"published_time":"2 years ago"},{"id":"Ugw1I89X4X0aVw37Brp4AaABAg","text":"Everybody who comments \"the algorithm brought me here\" needs to immediately like and subscribe. Thats how we can boost channels like this","author":"@gcrannell","author_id":"UCpnZDR1AXRsYtMcDw35hQHw","like_count":1,"published_time":"2 years ago"},{"id":"UgyQ5xOf7YTmJLDvagR4AaABAg","text":"I have been watching tech and programming channels for many years. This is the first time YouTube has recommended you. Glad to see it!","author":"@PaulEmsley","author_id":"UCbHAnhn_6MOmmjMMhR_0qkQ","like_count":10,"published_time":"2 years ago"},{"id":"UgxQn1SKh8yO_ciQy_54AaABAg","text":"weird way to propose but yes I accept","author":"@eduardoignacioroblessosa6349","author_id":"UCSDgxJoiZWswDOpph8sGn9w","like_count":2,"published_time":"2 years ago"},{"id":"UgyDOiM-YIy5EaE6ouZ4AaABAg","text":"OMG. Last time I wrote assembly was like 20 years ago! I love this woman!","author":"@sushiConPorotos","author_id":"UC1V0DFx7BlfCI9xVKPgQsOA","like_count":10,"published_time":"2 years ago"},{"id":"UgyHWJWuOK-uTLDe3yF4AaABAg","text":"I last coded in Arm for an Acorn Archimedes about 35 years ago. Thanks for the memory jolt.","author":"@CrestRising","author_id":"UCWbsTFBqosZXS2J_P-j4XCQ","like_count":1,"published_time":"2 years ago"},{"id":"Ugzv0nPUexcaoURHiRF4AaABAg","text":"Serial Experiments Lain! And the Wired. Wow!!! 😳 Awesome references. Just stumbled on this channel, so I wanted to acknowledge that. 😊","author":"@traal","author_id":"UC8kVxpH5j7I_613bRZ_d5ig","like_count":32,"published_time":"2 years ago"},{"id":"UgyKSncBdPsNdD792dx4AaABAg","text":"As someone who subscribes to a ton of tech-related channels, this is the first time YouTube recommended me to this channel.","author":"@chyldstudios","author_id":"UCoxgRBEk_fIKnlg_Qx8ughQ","like_count":396,"published_time":"2 years ago"},{"id":"Ugyt6Z4xGrMspdGvyKx4AaABAg","text":"Easily the greatest common divisor in the history of all common divisors","author":"@maisylover","author_id":"UCO_UB8B3SZ2M0uPZ0gp9aKQ","like_count":252,"published_time":"2 years ago"},{"id":"Ugx2A2jKZ5xI6NegQyl4AaABAg","text":"I was looking for something to snooze to and thought this was ASMR Assembly.","author":"@maelstrom57","author_id":"UC9BJqAqRlOJBAA0O4WYSmnw","like_count":77,"published_time":"2 years ago"},{"id":"UgxEwA0HYsWpnm94ol14AaABAg","text":"This is a great introduction and walk through for newcomers to assembly, but beware that the implementation has a quite significant flaw that will only reveal itself when called from other functions that have several live registers and happen to use r4 and store a value in it when it makes the call to this gcd function. The calling function will expect that the gcd function preserves the r4 register, as it is not a scratch register like r0-r3 are. This will manifest in miscalculations, unpredictable behavior and likely instability/crashes in the application using this function. An easy fix would be to push the r4 register along with lr to the stack, and pop it again (i.e. push {r4, lr} - pop {r4, pc}), but this of course increases the stack usage even more. Another approach would be to use r12 which is also a scratch register.\n\nIt would also be a good idea to make the implementation non-recursive as it can overflow the stack if it recurses too many times. For this algorithm this is quite easy as you can do tail call optimization by simply removing the push, replacing the pop by \"bx lr\" and doing a \"b gcd\" instead of \"bl gcd\" (which means the lr does not get overwritten for each iteration and retains the original return address that was written when the function was called the first time). This means the stack won't grow for each iteration.","author":"@ThomasThorsen","author_id":"UCrnn5DYsdOmhT13aXqqsUUg","like_count":97,"published_time":"2 years ago"},{"id":"UgwNKziAUmlG6AXRII14AaABAg","text":"praise the algorithm gods... how am i only just learning about this channel?","author":"@gcrannell","author_id":"UCpnZDR1AXRsYtMcDw35hQHw","like_count":48,"published_time":"2 years ago"},{"id":"UgydkMM5TmT0NWFIDOJ4AaABAg","text":"I finally watch Lain and now the Youtube algorithm is rewarding me","author":"@Summanis","author_id":"UC9hG-mlN6ktivoTLV7snN9Q","like_count":84,"published_time":"2 years ago"},{"id":"Ugz-7QdxrX4u307hjx14AaABAg","text":"I love the XP rice 😂","author":"@thejintent2770","author_id":"UCo_w3QOCgmvgW0bP6nyWlLw","like_count":10,"published_time":"2 years ago"},{"id":"UgzUmGw6JCivvaTQ6Ml4AaABAg","text":"Underrated channel. I cannot wait to get fat enough in my CS courses to understand this","author":"@mebibyte9347","author_id":"UCdhqpME4X4_bQB9Esg7pCtw","like_count":89,"published_time":"2 years ago"},{"id":"UgzbfKnwxE7CD2fZxQ54AaABAg","text":"The quality of the video and the content is top notch. Here before 1 M subscribers","author":"@ogphoenix8965","author_id":"UCo6f35f9M3xqAoGKM5OGwfg","like_count":20,"published_time":"2 years ago"},{"id":"UgxKy4C0T-wMsaqh_qp4AaABAg","text":"So it's been a few years since I was last writing in ARM asm (32-bit MCUs), so I might be a bit rusty... but I thought I saw a few tricks you'd missed, opened a notepad and downloaded an arm instruction-set reference and had a go myself. What I noticed:\n\n1: this is an ideal opportunity for tail recursion, simplifying the recursion to effectively a loop and removing the need to unwind the calls from the stack at the end\n2: move can set flags, removing the need to compare to determine zero both on entry and within the loop\n3: once you don't need to push/pop, bx lr can be used to return and can even be used with condition codes\n\n;; arm version\n\ngcd:\n\tmovs\tr1, r1\t\t;; mov can set flags? easiest way to get the z flag set for a zero input?\n\tbxeq\tlr\t\t\t;; conditional return. nice. assumes A32 instruction set tho...\n.loop:\n\tsdiv\t\tr2, r0, r1\t\t;; I find it surprising that ARM doesn't have some way to return\n\tmul\t\tr2, r2, r1\t\t;;  the remainder from a division... the bits are right there at the\n\tsub\t\tr2, r0, r2\t\t;;  end of the process, but then they get lost? and I have to recompute them? smh.\n\tmov\tr0, r1\t\t;; but even so, the ARM version is still smaller and neater than the x86,\n\tmovs\tr1, r2\t\t;;  which has to dance around the fixed register usage of its DIV instruction\n\tbne\t\tloop\t\t;; mov setting flags means that we can conditionally loop - also could set flags on the sub\n\tbx\t\tlr\t\t\t;; tail recursion means no push lr/pop pc, and we can use the direct return\n\n4: all this is very academic since most of the time will be in the div operation anyway...\n\n;; x86 version for comparison\n\ngcd:\t\t\t\t\t; expects a in edi, b in esi\n\tmov\teax, edi\n\ttest\t\tesi, esi\n\tjz\t\t.out\t\t\t;; no conditional return\n.loop:\n\txor\t\tedx, edx\t\t;; top half of dividand must be zeroed\n\tdiv\t\tesi\t\t\t;; div takes edx:eax as dividand, returns quotient in eax and remainder in edx\n\tmov\teax, esi\n\tmov\tesi, edx\n\ttest\t\tedx, edx\t\t;; have to use dedicated instruction for setting flags\n\tjnz\t\t.loop\t\t;; but at least these test/branch combo's get turned into a single µop when executed\n.out:\n\tret\t\t\t\t\t; return is in eax\n\n;;; the iterative logic as C\n\nint gcd(int a, int b) {\n\tif(!b) return a;\n\tint c;\n\twhile(c = a % b) { a = b; b = c; }\n\treturn b;\n}","author":"@treelibrarian7618","author_id":"UCFXKR8B0LqYQAGXNLWOuzBw","like_count":89,"published_time":"2 years ago"},{"id":"UgyKnvK90V3kgVl-wpd4AaABAg","text":"I don't know what the heckin flip I'm watching but I freakin know it's epic dude.","author":"@jonasc1221","author_id":"UC0-NCPzaT7XjGFdXAT4uXrA","like_count":1,"published_time":"2 years ago"},{"id":"UgwWLrufjJ5sbLDCkxF4AaABAg","text":"just in case, the modulo implementation works out if you use integer division not \"normal\" division\n(2//5)*5=0, but (2/5)*5=2","author":"@maydude2","author_id":"UCminbZdDmzr4QsUH1B5Fwyg","like_count":6,"published_time":"2 years ago"},{"id":"UgwEkRVspJzaseKBgLB4AaABAg","text":"Very nice walk-through! Small tip: if you ‘:set autoindent expandtab tabstop=8’, you can then use the <TAB> key to indent with spaces, and you will have a nicer vim experience.","author":"@edgarbonet1","author_id":"UC9KL7XU5j5HX-FbEJKJPtlg","like_count":1,"published_time":"11 months ago"},{"id":"UgxI0UdR8HAuTIewPzp4AaABAg","text":"looking for YouTuber making tutorial about arm assembly, never found, and tonight YouTube recommended this channel, okay YouTube, okay","author":"@hlodvic6678","author_id":"UCpvr8OL9OqXpkTIVp_y-Kxg","like_count":1,"published_time":"2 years ago"},{"id":"Ugw1I89X4X0aVw37Brp4AaABAg","text":"Everybody who comments \"the algorithm brought me here\" needs to immediately like and subscribe. Thats how we can boost channels like this","author":"@gcrannell","author_id":"UCpnZDR1AXRsYtMcDw35hQHw","like_count":1,"published_time":"2 years ago"},{"id":"UgyQ5xOf7YTmJLDvagR4AaABAg","text":"I have been watching tech and programming channels for many years. This is the first time YouTube has recommended you. Glad to see it!","author":"@PaulEmsley","author_id":"UCbHAnhn_6MOmmjMMhR_0qkQ","like_count":10,"published_time":"2 years ago"},{"id":"UgxQn1SKh8yO_ciQy_54AaABAg","text":"weird way to propose but yes I accept","author":"@eduardoignacioroblessosa6349","author_id":"UCSDgxJoiZWswDOpph8sGn9w","like_count":2,"published_time":"2 years ago"},{"id":"UgyDOiM-YIy5EaE6ouZ4AaABAg","text":"OMG. Last time I wrote assembly was like 20 years ago! I love this woman!","author":"@sushiConPorotos","author_id":"UC1V0DFx7BlfCI9xVKPgQsOA","like_count":10,"published_time":"2 years ago"},{"id":"UgyHWJWuOK-uTLDe3yF4AaABAg","text":"I last coded in Arm for an Acorn Archimedes about 35 years ago. Thanks for the memory jolt.","author":"@CrestRising","author_id":"UCWbsTFBqosZXS2J_P-j4XCQ","like_count":1,"published_time":"2 years ago"},{"id":"Ugzv0nPUexcaoURHiRF4AaABAg","text":"Serial Experiments Lain! And the Wired. Wow!!! 😳 Awesome references. Just stumbled on this channel, so I wanted to acknowledge that. 😊","author":"@traal","author_id":"UC8kVxpH5j7I_613bRZ_d5ig","like_count":32,"published_time":"2 years ago"},{"id":"UgyKSncBdPsNdD792dx4AaABAg","text":"As someone who subscribes to a ton of tech-related channels, this is the first time YouTube recommended me to this channel.","author":"@chyldstudios","author_id":"UCoxgRBEk_fIKnlg_Qx8ughQ","like_count":396,"published_time":"2 years ago"},{"id":"Ugyt6Z4xGrMspdGvyKx4AaABAg","text":"Easily the greatest common divisor in the history of all common divisors","author":"@maisylover","author_id":"UCO_UB8B3SZ2M0uPZ0gp9aKQ","like_count":252,"published_time":"2 years ago"},{"id":"Ugx2A2jKZ5xI6NegQyl4AaABAg","text":"I was looking for something to snooze to and thought this was ASMR Assembly.","author":"@maelstrom57","author_id":"UC9BJqAqRlOJBAA0O4WYSmnw","like_count":77,"published_time":"2 years ago"},{"id":"UgxEwA0HYsWpnm94ol14AaABAg","text":"This is a great introduction and walk through for newcomers to assembly, but beware that the implementation has a quite significant flaw that will only reveal itself when called from other functions that have several live registers and happen to use r4 and store a value in it when it makes the call to this gcd function. The calling function will expect that the gcd function preserves the r4 register, as it is not a scratch register like r0-r3 are. This will manifest in miscalculations, unpredictable behavior and likely instability/crashes in the application using this function. An easy fix would be to push the r4 register along with lr to the stack, and pop it again (i.e. push {r4, lr} - pop {r4, pc}), but this of course increases the stack usage even more. Another approach would be to use r12 which is also a scratch register.\n\nIt would also be a good idea to make the implementation non-recursive as it can overflow the stack if it recurses too many times. For this algorithm this is quite easy as you can do tail call optimization by simply removing the push, replacing the pop by \"bx lr\" and doing a \"b gcd\" instead of \"bl gcd\" (which means the lr does not get overwritten for each iteration and retains the original return address that was written when the function was called the first time). This means the stack won't grow for each iteration.","author":"@ThomasThorsen","author_id":"UCrnn5DYsdOmhT13aXqqsUUg","like_count":97,"published_time":"2 years ago"},{"id":"UgwNKziAUmlG6AXRII14AaABAg","text":"praise the algorithm gods... how am i only just learning about this channel?","author":"@gcrannell","author_id":"UCpnZDR1AXRsYtMcDw35hQHw","like_count":48,"published_time":"2 years ago"},{"id":"UgydkMM5TmT0NWFIDOJ4AaABAg","text":"I finally watch Lain and now the Youtube algorithm is rewarding me","author":"@Summanis","author_id":"UC9hG-mlN6ktivoTLV7snN9Q","like_count":84,"published_time":"2 years ago"},{"id":"Ugz-7QdxrX4u307hjx14AaABAg","text":"I love the XP rice 😂","author":"@thejintent2770","author_id":"UCo_w3QOCgmvgW0bP6nyWlLw","like_count":10,"published_time":"2 years ago"},{"id":"UgzUmGw6JCivvaTQ6Ml4AaABAg","text":"Underrated channel. I cannot wait to get fat enough in my CS courses to understand this","author":"@mebibyte9347","author_id":"UCdhqpME4X4_bQB9Esg7pCtw","like_count":89,"published_time":"2 years ago"},{"id":"UgzbfKnwxE7CD2fZxQ54AaABAg","text":"The quality of the video and the content is top notch. Here before 1 M subscribers","author":"@ogphoenix8965","author_id":"UCo6f35f9M3xqAoGKM5OGwfg","like_count":20,"published_time":"2 years ago"},{"id":"UgxKy4C0T-wMsaqh_qp4AaABAg","text":"So it's been a few years since I was last writing in ARM asm (32-bit MCUs), so I might be a bit rusty... but I thought I saw a few tricks you'd missed, opened a notepad and downloaded an arm instruction-set reference and had a go myself. What I noticed:\n\n1: this is an ideal opportunity for tail recursion, simplifying the recursion to effectively a loop and removing the need to unwind the calls from the stack at the end\n2: move can set flags, removing the need to compare to determine zero both on entry and within the loop\n3: once you don't need to push/pop, bx lr can be used to return and can even be used with condition codes\n\n;; arm version\n\ngcd:\n\tmovs\tr1, r1\t\t;; mov can set flags? easiest way to get the z flag set for a zero input?\n\tbxeq\tlr\t\t\t;; conditional return. nice. assumes A32 instruction set tho...\n.loop:\n\tsdiv\t\tr2, r0, r1\t\t;; I find it surprising that ARM doesn't have some way to return\n\tmul\t\tr2, r2, r1\t\t;;  the remainder from a division... the bits are right there at the\n\tsub\t\tr2, r0, r2\t\t;;  end of the process, but then they get lost? and I have to recompute them? smh.\n\tmov\tr0, r1\t\t;; but even so, the ARM version is still smaller and neater than the x86,\n\tmovs\tr1, r2\t\t;;  which has to dance around the fixed register usage of its DIV instruction\n\tbne\t\tloop\t\t;; mov setting flags means that we can conditionally loop - also could set flags on the sub\n\tbx\t\tlr\t\t\t;; tail recursion means no push lr/pop pc, and we can use the direct return\n\n4: all this is very academic since most of the time will be in the div operation anyway...\n\n;; x86 version for comparison\n\ngcd:\t\t\t\t\t; expects a in edi, b in esi\n\tmov\teax, edi\n\ttest\t\tesi, esi\n\tjz\t\t.out\t\t\t;; no conditional return\n.loop:\n\txor\t\tedx, edx\t\t;; top half of dividand must be zeroed\n\tdiv\t\tesi\t\t\t;; div takes edx:eax as dividand, returns quotient in eax and remainder in edx\n\tmov\teax, esi\n\tmov\tesi, edx\n\ttest\t\tedx, edx\t\t;; have to use dedicated instruction for setting flags\n\tjnz\t\t.loop\t\t;; but at least these test/branch combo's get turned into a single µop when executed\n.out:\n\tret\t\t\t\t\t; return is in eax\n\n;;; the iterative logic as C\n\nint gcd(int a, int b) {\n\tif(!b) return a;\n\tint c;\n\twhile(c = a % b) { a = b; b = c; }\n\treturn b;\n}","author":"@treelibrarian7618","author_id":"UCFXKR8B0LqYQAGXNLWOuzBw","like_count":89,"published_time":"2 years ago"},{"id":"UgyKnvK90V3kgVl-wpd4AaABAg","text":"I don't know what the heckin flip I'm watching but I freakin know it's epic dude.","author":"@jonasc1221","author_id":"UC0-NCPzaT7XjGFdXAT4uXrA","like_count":1,"published_time":"2 years ago"},{"id":"UgwWLrufjJ5sbLDCkxF4AaABAg","text":"just in case, the modulo implementation works out if you use integer division not \"normal\" division\n(2//5)*5=0, but (2/5)*5=2","author":"@maydude2","author_id":"UCminbZdDmzr4QsUH1B5Fwyg","like_count":6,"published_time":"2 years ago"},{"id":"UgwEkRVspJzaseKBgLB4AaABAg","text":"Very nice walk-through! Small tip: if you ‘:set autoindent expandtab tabstop=8’, you can then use the <TAB> key to indent with spaces, and you will have a nicer vim experience.","author":"@edgarbonet1","author_id":"UC9KL7XU5j5HX-FbEJKJPtlg","like_count":1,"published_time":"11 months ago"},{"id":"UgxI0UdR8HAuTIewPzp4AaABAg","text":"looking for YouTuber making tutorial about arm assembly, never found, and tonight YouTube recommended this channel, okay YouTube, okay","author":"@hlodvic6678","author_id":"UCpvr8OL9OqXpkTIVp_y-Kxg","like_count":1,"published_time":"2 years ago"},{"id":"Ugw1I89X4X0aVw37Brp4AaABAg","text":"Everybody who comments \"the algorithm brought me here\" needs to immediately like and subscribe. Thats how we can boost channels like this","author":"@gcrannell","author_id":"UCpnZDR1AXRsYtMcDw35hQHw","like_count":1,"published_time":"2 years ago"},{"id":"UgyQ5xOf7YTmJLDvagR4AaABAg","text":"I have been watching tech and programming channels for many years. This is the first time YouTube has recommended you. Glad to see it!","author":"@PaulEmsley","author_id":"UCbHAnhn_6MOmmjMMhR_0qkQ","like_count":10,"published_time":"2 years ago"},{"id":"UgxQn1SKh8yO_ciQy_54AaABAg","text":"weird way to propose but yes I accept","author":"@eduardoignacioroblessosa6349","author_id":"UCSDgxJoiZWswDOpph8sGn9w","like_count":2,"published_time":"2 years ago"},{"id":"UgyDOiM-YIy5EaE6ouZ4AaABAg","text":"OMG. Last time I wrote assembly was like 20 years ago! I love this woman!","author":"@sushiConPorotos","author_id":"UC1V0DFx7BlfCI9xVKPgQsOA","like_count":10,"published_time":"2 years ago"},{"id":"UgyHWJWuOK-uTLDe3yF4AaABAg","text":"I last coded in Arm for an Acorn Archimedes about 35 years ago. Thanks for the memory jolt.","author":"@CrestRising","author_id":"UCWbsTFBqosZXS2J_P-j4XCQ","like_count":1,"published_time":"2 years ago"},{"id":"Ugzv0nPUexcaoURHiRF4AaABAg","text":"Serial Experiments Lain! And the Wired. Wow!!! 😳 Awesome references. Just stumbled on this channel, so I wanted to acknowledge that. 😊","author":"@traal","author_id":"UC8kVxpH5j7I_613bRZ_d5ig","like_count":32,"published_time":"2 years ago"}]}