frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

Why xor eax, eax?

https://xania.org/202512/01-xor-eax-eax
89•hasheddan•1h ago

Comments

daeken•39m ago
Back in 2005 or 2006, I was working at a little startup with "DVD Jon" Johansen and we'd have Quake 3 tournaments to break up the monotony of reverse-engineering and juggling storage infrastructure. His name was always "xor eax,eax" and I always just had to laugh at the idea of getting zeroed out by someone with that name. (Which happened a lot -- I was good, but he was much better!)
OgsyedIE•34m ago
The page crashes after 3 seconds, 100% of the time, on the latest version of Android Chrome and works fine on Brave, fyi.
robmccoll•29m ago
This is not my experience on the latest version of Chrome Android (142.0.7444.171). It did not crash for me.
pansa2•33m ago
> Unlike other partial register writes, when writing to an e register like eax, the architecture zeros the top 32 bits for free.

I’m familiar with 32-bit x86 assembly from writing it 10-20 years ago. So I was aware of the benefit of xor in general, but the above quote was new to me.

I don’t have any experience with 64-bit assembly - is there a guide anywhere that teaches 64-bit specifics like the above? Something like “x64 for those who know x86”?

veltas•21m ago
Chapter 3 of volume 1, ctrl+f for "64-bit mode", has a lot of the essentials including e.g. the stuff about zeroing out the top half of the register.

https://www.intel.com/content/www/us/en/developer/articles/t...

matt_d•12m ago
See https://github.com/MattPD/cpplinks/blob/master/assembly.x86.... - mostly focused on x86-64 (and some of the talks/tutorials offer pretty good overview)
snvzz•28m ago
Because, unlike RISC-V, x86 has no x0 register.
jabl•15m ago
From your past posting history, I presume that you're implying this makes RISC-V better?

Do we have any data showing that having a dedicated zero register is better than a short and canonical instruction for zeroing an arbitrary register?

kevin_thibedeau•8m ago
It's a definite liability on a machine with only 8 general purpose registers. Losing 12% of the register space for a constant would be a waste of hardware.
dooglius•2m ago
I think one could just pick a convention where a particular GP register is zeroed at program startup and just make your own zero register that way, getting all the benefits at very small cost. The microarchitecture AIUI has a dedicated zero register so any processor-level optimizations would still apply.
omnicognate•23m ago
It happens to be the first instruction of the first snippet in the wonderful xchg rax, rax.

https://www.xorpd.net/pages/xchg_rax/snip_00.html

dooglius•11m ago
Not sure what I am looking at here is this just a bunch of different ways to zero registers?
eb0la•22m ago
I remember a lot of code zeroing registrers, dating at least back from the IBM PC XT days (before the 80286).

If you decode the instruction, it makes sense to use XOR:

- mov ax, 0 - needs 4 bytes (66 b8 00 00) - xor ax,ax - needs 3 bytes (66 31 c0)

This extra byte in a machine with less than 1 Megabyte of memory did id matter.

In 386 processors it was also - mov eax,0 - needs 5 bytes (b8 00 00 00 00) - xor eax,eax - needs 2 bytes (31 c0)

Here Intel made the decision to use only 2 bytes. I bet this helps both the instruction decoder and (of course) saves more memory than the old 8086 instruction.

vardump•14m ago
> - mov ax, 0 - needs 4 bytes (66 b8 00 00) - xor ax,ax - needs 3 bytes (66 31 c0)

You don't need operand size prefix 0x66 when running 16 bit code in Real Mode. So "mov ax, 0" is 3 bytes and "xor ax, ax" is just 2 bytes.

deadcore•20m ago
Matt Godbolt also uploads to his self titled Youtube channel: https://www.youtube.com/watch?v=eLjZ48gqbyg
pclmulqdq•18m ago
In modern CPUs, a lot of these are recognized as zeroing idioms and they end up doing the same thing (often a register renaming trick). Using the shortest one makes sense. If you use a really weird zeroing pattern, you can also see it as a backend uop while many of these zeroing idioms are elided by the frontend on some cores.
Dwedit•15m ago
Because "sub eax,eax" looks stupid. (and also clears the carry flag, unlike "xor eax, eax")
sylware•3m ago
Remnant of RISC attempt without a zero register.

Why xor eax, eax?

https://xania.org/202512/01-xor-eax-eax
89•hasheddan•1h ago•20 comments

Self-hosting a Matrix server for 5 years

https://yaky.dev/2025-11-30-self-hosting-matrix/
95•the-anarchist•2h ago•34 comments

Search tool that only returns content created before ChatGPT's public release

https://tegabrain.com/Slop-Evader
566•dmitrygr•9h ago•221 comments

Games using anti-cheats and their compatibility with GNU/Linux or Wine/Proton

https://areweanticheatyet.com/
101•doener•6h ago•102 comments

Advent of Code 2025

https://adventofcode.com/2025/about
1053•vismit2000•1d ago•340 comments

Detection of triboelectric discharges during dust events on Mars

https://gizmodo.com/weve-detected-lightning-on-mars-for-the-first-time-2000691996
71•domofutu•4d ago•38 comments

It’s been a very hard year

https://bell.bz/its-been-a-very-hard-year/
169•surprisetalk•8h ago•176 comments

A Love Letter to FreeBSD

https://www.tara.sh/posts/2025/2025-11-25_freebsd_letter/
354•rbanffy•15h ago•219 comments

Trifold is a tool to quickly and cheaply host static websites using a CDN

https://www.jpt.sh/projects/trifold/
50•birdculture•1w ago•10 comments

Writing a good Claude.md

https://www.humanlayer.dev/blog/writing-a-good-claude-md
585•objcts•19h ago•213 comments

Advent of Sysadmin 2025

https://sadservers.com/advent
278•lazyant•12h ago•80 comments

1GB Raspberry Pi 5, and memory-driven price rises

https://www.raspberrypi.com/news/1gb-raspberry-pi-5-now-available-at-45-and-memory-driven-price-r...
74•shrx•2h ago•36 comments

DeepSeekMath-V2: Towards Self-Verifiable Mathematical Reasoning

https://huggingface.co/deepseek-ai/DeepSeek-Math-V2
180•victorbuilds•5h ago•60 comments

SmartTube Compromised

https://www.aftvnews.com/smarttubes-official-apk-was-compromised-with-malware-what-you-should-do-...
103•akersten•8h ago•75 comments

Dancing rope and braid into being (2017) [pdf]

https://archive.bridgesmathart.org/2017/bridges2017-523.pdf
15•surprisetalk•6d ago•0 comments

N-Body Simulator – Interactive 3 Body Problem and Gravitational Physics

https://trisolarchaos.com/?pr=lagrange&n=3&s=5.0&so=0.01&im=verlet&dt=5.00e-4&rt=1.0e-6&at=1.0e-8...
76•speckx•6d ago•13 comments

X210Ai is a new motherboard to upgrade ThinkPad X201/200

https://www.tpart.net/about-x210ai/
123•walterbell•10h ago•42 comments

Algorithms for Optimization [pdf]

https://algorithmsbook.com/optimization/files/optimization.pdf
293•Anon84•14h ago•26 comments

Google Antigravity just deleted the contents of whole drive

https://old.reddit.com/r/google_antigravity/comments/1p82or6/google_antigravity_just_deleted_the_...
324•tamnd•9h ago•239 comments

Windows drive letters are not limited to A-Z

https://www.ryanliptak.com/blog/windows-drive-letters-are-not-limited-to-a-z/
462•LorenDB•1d ago•235 comments

Victorian-style lines for the web: Elements of identical width

https://jacobfilipp.com/victorian-line/
8•surprisetalk•6d ago•1 comments

Engineers repurpose a mosquito proboscis to create a 3D printing nozzle

https://techxplore.com/news/2025-11-repurpose-mosquito-proboscis-3d-nozzle.html
69•T-A•4d ago•28 comments

Migrating Dillo from GitHub

https://dillo-browser.org/news/migration-from-github/
384•todsacerdoti•23h ago•193 comments

GitHub to Codeberg: my experience

https://eldred.fr/blog/forge-migration/
297•todsacerdoti•21h ago•113 comments

Replacing My Window Manager with Google Chrome

https://foxmoss.com/blog/dote/
76•foxmoss•3d ago•17 comments

Accenture dubs 800k staff 'reinventors' amid shift to AI

https://www.theguardian.com/business/2025/dec/01/accenture-rebrands-staff-reinventors-ai-artifici...
38•n1b0m•3h ago•15 comments

Ly – A lightweight TUI (ncurses-like) display manager for Linux and BSD

https://codeberg.org/fairyglade/ly
72•modinfo•13h ago•11 comments

UK Government plans new powers to label dissenting movements as 'subversion'

https://netpol.org/2025/11/28/government-plans-new-powers-to-label-dissenting-movements-as-subver...
98•robtherobber•2h ago•79 comments

WhatsApp will become interoperable with other messaging apps

https://tuta.com/blog/whatsapp-interoperable-in-europe
10•marvinborner•32m ago•3 comments

Cuddle Fish – A Soft Floating Robot for Safe Physical Interaction

https://kaikunze.de/post/2025-11.18-cuddle-fish/
8•kgarten•1w ago•5 comments