duangsuse::Echo
718 subscribers
4.26K photos
130 videos
583 files
6.48K links
import this:
美而不丑、明而不暗、短而不凡、长而不乱,扁平不宽,读而后码,行之天下,勿托地上天国。
异常勿吞,难过勿过,叹一真理。效率是很重要,盲目最是低效。
简明是可靠的先验,不是可靠的祭品。
知其变,守其恒,为天下式;穷其变,知不穷,得地上势。知变守恒却穷变知新,我认真理,我不认真。

技术相干订阅~
另外有 throws 闲杂频道 @dsuset
转载频道 @dsusep
极小可能会有批评zf的消息 如有不适可退出
suse小站(面向运气编程): https://WOJS.org/#/
Download Telegram
This media is not supported in your browser
VIEW IN TELEGRAM
Lexer 的事情不知道靠 scanf() 有没用了... 毕竟我没有写过这种,或许就只能读取全部到 std::string 然后再扫描了呢
「作弊」永远是解决问题的最好途径,也是我每次能最快解决问题的方式,所以我希望大家以后遇事不要先问人,先问鸭子得到答案更快
扫描的时候有编码问题...
    int c;
while ((c = getchar()) != EOF) {
code.append((const char *) &c);
}

我的锅,把指针递出去了,看看 << 操作符能不能用...
This media is not supported in your browser
VIEW IN TELEGRAM
接下来要写解析器逻辑,因为表达式都是毕竟简单的格式

因为我对 C++ 和结合实在是可以说几乎一无所知,所以暂时不做运算符优先级了,以后慢慢思考

表达式都是这样的

1 + 1 * 2 / 3
2 * 233

编译出来是这个样子(1 + 1 为例)
This media is not supported in your browser
VIEW IN TELEGRAM
我还以为 8085 按道理应该是 8086 的近亲呢... 没想到指令数目比 8086 少那么多,连除法都要用户做....
GNUSim8085 好像没有办法直接「往标准输出输出」...
无话可说
终于会用这玩意了... 真好用啊
This media is not supported in your browser
VIEW IN TELEGRAM
第一次知道 radare2 这个著名泥像框架还可以用来调试程序...
总是 segfault...
... 现在还不能算三年血赚猝死不亏
hello.S

.section .rodata

hello_world: .string "你好,世界!\n"

.section .text

.globl _start

_start:
call main # call assembly main

mov $60, %rax # sys_exit
mov $0, %rdi # exit status

syscall # make call

sysprintf:
mov %rsp, %rbp # stdcall

mov $1, %rax # sys_write
mov $1, %rdi # use stdout

pop %rsi # string ptr
pop %rdx # length

syscall

ret

main:
mov %rsp, %rbp

mov $hello_world, %rax
dec %rax

push %rax
push $20
call sysprintf

ret

Makefile

hello: hello.S
as hello.S -o hello.o
ld -o hello hello.o -lc -I /usr/lib64/ld-2*.so

clean:
rm -f hello hello.o


.PHONY: clean


执行时

[DuangSUSE@duangsuse asm-foo]$ ldd hello
linux-vdso.so.1 (0x00007fffe01b7000)
libc.so.6 => /lib64/libc.so.6 (0x00007f9e9e68c000)
/usr/lib64/ld-2.27.so => /lib64/ld-linux-x86-64.so.2 (0x00007f9e9ea4b000)

hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /usr/lib64/ld-2.27.so, not stripped

9: 0000000000000000 0 FILE LOCAL DEFAULT ABS hello.o
10: 000000000040021c 0 NOTYPE LOCAL DEFAULT 6 hello_world
11: 0000000000400206 0 NOTYPE LOCAL DEFAULT 5 main
12: 00000000004001f0 0 NOTYPE LOCAL DEFAULT 5 sysprintf

[DuangSUSE@duangsuse asm-foo]$ ./hello
�你好,世界!


... 虽然还有一点小问题,比如不知道为何字符串指针减少一位后才能不 SegFault 否则 会在 main 的 ret 治疗执行时无法正常跳转
和每次执行时 Zsh 都会吐出一个不知名符号出来外,通宵血赚,鸽子不亏 😶
This media is not supported in your browser
VIEW IN TELEGRAM
另外我有点「x86 和 8085 那类机器以及 arm 系列更简单」的感觉

毕竟 ARM 是 RISC 嘛,但 ARM 还不至于到除法都要手动汇编子过程解决