Cpu Work (2)
dev.to·2d·
Discuss: DEV

Continue on how CPU works. As we already know that CPU only knows numbers and calculate number. And So a natural question is "how CPU loops and create condition if the CPU only know how to calculate?".

To put it simply, CPUs have special instructions that allow them to jump between instructions. We can "emulate" loop and condition, for example in my CPU simulation i have this instruction called JZ (jump if zero). As the name suggests, it jumps to another instruction if a certain value is zero.

example:

LOAD A, 1
LOAD B, 1

CMP A, B
JZ exit
STOREM A, 0 ; store value register A to memory
exit:

HALT

At this point, a question appears: "what value does JZ actually check?" we know that exit is just a label on which line it’s referring to, not a value. So how…

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help