I wonder if the history of x86 is holding us back in a big way. It started out being close to the metal but now it's an abstraction that can mislead you if you think processors are literally working the way x86 assembly describes. And surely the whole spectre issue could be lessened if we could be less reliant on CPUs having to guess what to keep in cache, which code paths are most likely, etc?
> I wonder if the history of x86 is holding us back in a big way. It started out being close to the metal but now it's an abstraction that can mislead you if you think processors are literally working the way x86 assembly describes. But when you compare high-end cores, you always see the same picture, regardless of ISA. Large surface area (~1/3 of the core) used for insn fetch/decode/schedule; they look all the same,…
X86 assembly doesn’t have to be scary
51–60 of 129 posts
Re: X86 assembly doesn’t have to be scary
#52Earlier quoted context omitted.
I agree with you to an extent: The IBM PC was not a very elegant design, and other computers certainly had less complexity to them. But there is a point I want to make which defends this choice somewhat: Newbies like me are more frustrated by thinking there's no path from introductory material to something useful or realistic. Something that's more immediately friendly would be a simplified virtual machine with no or…
Well, I had in mind something more useful and realistic, not less; namely teaching assembly in normal Linux environment. Sure, there are all sorts of complexities there too, but in general I feel like they are also more worthwhile.
"Sshtalk: An SSH-based chat made in assembler" : https://news.ycombinator.com/item?id=15829206
The library comes with a lot, but network stuff and Unicode support to name a few:
Re: X86 assembly doesn’t have to be scary
#53Re: X86 assembly doesn’t have to be scary
#54What would be more interesting is the UEFI boot process. I don't think any new computer comes booting into 16bit real mode anymore. I would love to see a "Write your own UEFI bootable kernel" I'm sure going straight to a semi sane 32bit environment is much easier to deal with than starting at 16 and working your way up.
It most certainly does. See the chapter on 8086 emulation in the Intel Software Developer's Manual, Volume 3.
Re: X86 assembly doesn’t have to be scary
#55When I was about 14 I was enthralled with programming my new Commodore 64, first in BASIC, then 6510 assembly. I had the opportunity to accompany my mother to a one-day class on programming. Being just an intro on the subject, I was well ahead of what they would be discussing, but thought it would interesting to talk to some adults that were also into programming. I was talking to a couple of guys about what I had be…
>"How can you possibly write anything with only three registers?!" AFAIK you can even go down to 1 register, which is how stack machines work. You might even say it’s 0 registers because it’s not something you can directly access.
Wikipedia has a section on accumulator machines: https://en.wikipedia.org/wiki/Accumulator_(computing)#Accumu...
Assuming Wikipedia's article on the PDP-8 is correct, the PDP-8 had just two public registers: the program counter, and the general-purpose 'accumulator' register.
Re: X86 assembly doesn’t have to be scary
#56Earlier quoted context omitted.
> I wonder if the history of x86 is holding us back in a big way. It started out being close to the metal but now it's an abstraction that can mislead you if you think processors are literally working the way x86 assembly describes. But when you compare high-end cores, you always see the same picture, regardless of ISA. Large surface area (~1/3 of the core) used for insn fetch/decode/schedule; they look all the same,…
Even 15 decoders are a pinprick on the core’s area—at least when I saw die area for LRB. Fetch & schedule we’re a bit larger. Most of the core area was register files & floating-vector logic.
What is LRB?
Re: X86 assembly doesn’t have to be scary
#57Earlier quoted context omitted.
But then there's that "msg.len", which I assume is some sort of assembler shortcut for getting the length of an array and not part of the x86.
That's referring to the label msg.len, which is a value computed at compile time in the 'data' section at the bottom. msg: db "Hello, world!", 10 .len: equ $ - msg 'msg' is a label, which will be assigned to an address at compile time. 'db' short for 'declare bytes' puts some bytes at that address. '.len' is then defined as the current output address ($) minus the start of the string.
cat hello.c
#include
char str[] = "Hello, World!\n";
int main() {
write(1, str, sizeof(str)-1);
return 0;
}
cat hello.s .file "hello.c"
.intel_syntax noprefix
.globl str
.data
.align 8
.type str, @object
.size str, 15
str:
.string "Hello, World!\n"
.text
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
push rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
mov rbp, rsp
.cfi_def_cfa_register 6
mov edx, 14
lea rsi, str[rip]
mov edi, 1
call write@PLT
mov eax, 0
pop rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE0:
.size main, .-main
.ident "GCC: (Ubuntu 7.2.0-8ubuntu3.2) 7.2.0"
.section .note.GNU-stack,"",@progbits
Note the line: lea rsi, str[rip]
which I belive is something along the lines of load effective address (lea), into rsi register, of "str" symbol offset with relative instruction pointer (rip - to allow for relative addressing).You can compile and run with:
gcc -std=c11 hello.c && ./a.out
Prouduce hello.s from hello.c with: gcc -std=c11 hello.c -S -masm=intel
Re: X86 assembly doesn’t have to be scary
#58Re: X86 assembly doesn’t have to be scary
#59Earlier quoted context omitted.
That's referring to the label msg.len, which is a value computed at compile time in the 'data' section at the bottom. msg: db "Hello, world!", 10 .len: equ $ - msg 'msg' is a label, which will be assigned to an address at compile time. 'db' short for 'declare bytes' puts some bytes at that address. '.len' is then defined as the current output address ($) minus the start of the string.
In addition to all these excellent comments, it can also be instructive to go "backwards" from C, here on Linux: cat hello.c #include char str[] = "Hello, World!\n"; int main() { write(1, str, sizeof(str)-1); return 0; } cat hello.s .file "hello.c" .intel_syntax noprefix .globl str .data .align 8 .type str, @object .size str, 15 str: .string "Hello, World!\n" .text .globl main .type main, @function main: .LFB0: .cfi_…
Re: X86 assembly doesn’t have to be scary
#60I wonder if the history of x86 is holding us back in a big way. It started out being close to the metal but now it's an abstraction that can mislead you if you think processors are literally working the way x86 assembly describes. And surely the whole spectre issue could be lessened if we could be less reliant on CPUs having to guess what to keep in cache, which code paths are most likely, etc?