Timeline for The Luhn algorithm for verifying credit card numbers, etc
Current License: CC BY-SA 4.0
27 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jan 14, 2021 at 3:19 | comment | added | Cody Gray |
Oh, right, duh. You just want loop, not loopz. I was for some reason thinking that dec didn't set zf, but it's actually cf that it doesn't set.
|
|
| Jan 14, 2021 at 3:18 | comment | added | 640KB |
@CodyGray so I don't think it's going to be a drop-in change... loopz is an AND condition - branch if cx non-zero and zf is 1. So in other words would still need to set zf somewhere first. Though, it's an interesting idea to see if it can be refactored to set that flag another way in an operation already being done. Will have to try that later on!
|
|
| Jan 13, 2021 at 23:52 | comment | added | Cody Gray |
You'd probably also like to read the novels that I dream up while sleeping, too. I'll let you know. :-p In your second submission, could the 3-byte dec cx + jz done be replaced with a 2-byte loopz done?
|
|
| Jan 13, 2021 at 18:36 | comment | added | 640KB |
@CodyGray I played with the idea of iterating forwards using the Wiki-inspired if ( originalCx & 1 == currentCx & 1 ) then..., but got a bit fiddly in ASM and was longer for me. Then I tried loading two bytes at a time (while still going backwards) and got it down to +2 bytes longer than the original. Posted it anyway in case it inspires another idea. Would love to see the answer you "dreamed" up too! :)
|
|
| Jan 13, 2021 at 18:29 | history | edited | 640KB | CC BY-SA 4.0 |
add alternate (but longer) version
|
| Jan 13, 2021 at 14:27 | history | edited | 640KB | CC BY-SA 4.0 |
+4 bytes, rules compliance
|
| Jan 13, 2021 at 14:16 | comment | added | 640KB |
@CodyGray my quick reading of the Wiki implementation, it seems to first determine if the number of digits is odd or even (parity := nDigits modulus 2) and then checks every time through the loop if that index corresponds to a relative odd or even index (if i modulus 2 = parity). Maybe that could be golfed, though I tend to think the 3 bytes to start from the end isn't too bad. Also, it looks like I'm going to have to take a +4 bytes penalty to get this submission up to spec with the rules. I guess I didn't quite understand them when I wrote this one. :)
|
|
| Jan 13, 2021 at 4:58 | comment | added | Cody Gray |
Yeah, I realize it's an old answer. The Luhn algorithm was brought up in a chat room earlier, so I was considering it, dreaming of it in x86 asm. I decided to check Code Golf, and sure enough, it was already here. With a pretty solid-looking x86 asm answer. Thus, I immediately set out to nitpick. ;-) We were specifically discussing whether it is necessary to iterate backwards. The reference implementation in pseudocode on Wikipedia doesn't appear to go backwards. Didn't even notice about the missing ret though. Would take some effort to clean up, probably more than it's worth.
|
|
| Jan 13, 2021 at 1:57 | comment | added | 640KB | @CodyGray IIRC I think it has to do with having an odd number of digits, and the LUHN algorithm expecting you to operate on the last digits first. Maybe I should take another look though... | |
| Jan 13, 2021 at 1:40 | comment | added | Cody Gray |
I haven't spent very long staring at this, but... Why do you need to iterate through the string backwards? If you iterated forwards, it seems like you'd get the same result, but be able to shave off those initial 3 bytes (setting SI and the direction flag [which you can assume is always clear]).
|
|
| Jun 17, 2020 at 9:04 | history | edited | Community Bot |
Commonmark migration
|
|
| Nov 8, 2019 at 16:45 | history | edited | 640KB | CC BY-SA 4.0 |
remove unnecesary MACRO syntax, cleanup unnecssary explanation
|
| Mar 26, 2019 at 21:36 | history | edited | 640KB | CC BY-SA 4.0 |
clarify program comments and formatting
|
| Mar 26, 2019 at 19:57 | history | edited | 640KB | CC BY-SA 4.0 |
added 2 characters in body
|
| Mar 26, 2019 at 19:51 | history | edited | 640KB | CC BY-SA 4.0 |
-2 bytes, don't need to worry about 8 bit overflow since we're doing mod 10... duh
|
| Mar 26, 2019 at 19:38 | history | edited | 640KB | CC BY-SA 4.0 |
add explanation for register state
|
| Mar 26, 2019 at 19:29 | history | edited | 640KB | CC BY-SA 4.0 |
edited body
|
| Mar 26, 2019 at 19:23 | history | edited | 640KB | CC BY-SA 4.0 |
add link to platform referebce
|
| Mar 26, 2019 at 19:14 | history | edited | 640KB | CC BY-SA 4.0 |
-3 bytes, use DX register for flip/flop (DOS init's DX to CS - a positive, non-zero value)
|
| Mar 26, 2019 at 17:55 | history | edited | 640KB | CC BY-SA 4.0 |
-1 byte
|
| Mar 26, 2019 at 17:50 | history | edited | 640KB | CC BY-SA 4.0 |
-1 byte
|
| Mar 26, 2019 at 17:40 | history | edited | 640KB | CC BY-SA 4.0 |
deleted 3 characters in body
|
| Mar 26, 2019 at 16:36 | history | edited | 640KB | CC BY-SA 4.0 |
deleted 6 characters in body
|
| Mar 26, 2019 at 16:26 | history | edited | 640KB | CC BY-SA 4.0 |
deleted 6 characters in body
|
| Mar 26, 2019 at 16:17 | history | edited | 640KB | CC BY-SA 4.0 |
edited body
|
| Mar 26, 2019 at 16:11 | history | edited | 640KB | CC BY-SA 4.0 |
-6 bytes, use AAM for mod 10 test
|
| Mar 26, 2019 at 16:03 | history | answered | 640KB | CC BY-SA 4.0 |