《Programming from the Ground Up》阅读笔记:p117-p146

简介: 《Programming from the Ground Up》阅读笔记:p117-p146

《Programming from the Ground Up》学习第8天,p117-p146总结,总计30页。

一、技术总结
1.共享函数用法示例
(1)不使用共享函数
linux.s:

filename:linux.s

system call numbers(按数字大小排列,方便查看)

.equ SYS_READ, 0
.equ SYS_WRITE, 1
.equ SYS_OPEN, 2
.equ SYS_CLOSE, 3
.equ SYS_EXIT, 60

standard file descriptors

.equ STDIN, 0
.equ STDOUT, 1
.equ STDERR, 2

common status codes

.equ END_OF_FILE, 0
helloworld-nolib.s:

filename: helloworld-nolib.s

编译命令:

as helloworld-nolib.s -o helloworld-nolib.o

ld helloworld-nolib.o -o helloworld-lib

.include "linux.s"

.section .data
helloworld:
.ascii "hello world\n"
helloworld_end:

#helloworld_end - helloworld的意思:
.equ helloworld_len, helloworld_end - helloworld

.section .text
.global _start

_start:

#write涉及到SYS_WRITE,
movq  $SYS_WRITE, %rax
movq  $STDOUT, %rdi
movq  $helloworld, %rsi
movq  $helloworld_len, %rdx
syscall

# 退出函数: exit()
movq  $SYS_EXIT, %rax
movq  $0, %rdi
syscall

执行helloworld-nolib结果:

./helloworld-nolib

hello world
(2)使用共享函数:print、exit
helloworld-lib.s:

filename: helloworld-lib.s

编译命令:

as helloworld-lib.s -o helloworld-lib.o

ld -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o helloworld-lib helloworld-lib.o -lc

.section .data
helloworld:
.ascii "hello world\n\0"

.section .text
.globl _start

_start:
movq $helloworld, %rdi
call printf # C语言中的printf
movq $0, %rdi
call exit # C语言中的exit
执行helloworld-lib结果:

./helloworld-nolib

hello world
2.问题:-bash: ./helloworld-lib: No such file or directory
问题描述

root@LAPTOP-5PGRQ2IO:/mnt/d/Projects/AssemblyProjects# ld -dynamic-linker /lib/ld-linux.so.2 -o helloworld-lib helloworld-lib.o -lc
root@LAPTOP-5PGRQ2IO:/mnt/d/Projects/AssemblyProjects# ll
total 96
drwxrwxrwx 1 root root 4096 Sep 28 15:48 ./
drwxrwxrwx 1 root root 4096 Jun 24 07:23 ../
-rwxrwxrwx 1 root root 147 Aug 25 16:18 add-year.s
-rwxrwxrwx 1 root root 1075 Aug 31 18:55 count-chars.s

-rwxrwxrwx 1 root root 112 Aug 25 16:26 error-exit.s
-rwxrwxrwx 1 root root 863 Jul 1 23:39 exit.s

-rwxrwxrwx 1 root root 14048 Sep 28 15:48 helloworld-lib
-rwxrwxrwx 1 root root 920 Sep 28 15:47 helloworld-lib.o

-rwxrwxrwx 1 root root 224 Sep 2 08:43 helloworld-lib.s
-rwxrwxrwx 1 root root 9224 Sep 28 15:44 helloworld-nolib

-rwxrwxrwx 1 root root 1208 Sep 2 08:39 helloworld-nolib.o
-rwxrwxrwx 1 root root 510 Sep 2 08:39 helloworld-nolib.s

-rwxrwxrwx 1 root root 264 Aug 24 17:52 linux.s
-rwxrwxrwx 1 root root 774 Jul 3 06:25 maximum.s

drwxrwxrwx 1 root root 4096 Aug 25 16:20 pgu_64-master/
-rwxrwxrwx 1 root root 2318 Jul 16 07:52 power.s
-rwxrwxrwx 1 root root 453 Aug 24 18:14 read-record.s

-rwxrwxrwx 1 root root 1333 Aug 24 18:15 read-records.s
-rwxrwxrwx 1 root root 117 Aug 23 08:23 record-def.s

-rwxrwxrwx 1 root root 984 Aug 24 17:58 test.dat
-rwxrwxrwx 1 root root 5612 Jul 27 11:47 toupper.s

-rwxrwxrwx 1 root root 1128 Aug 24 17:57 write-record.o
-rwxrwxrwx 1 root root 686 Aug 24 17:54 write-record.s

-rwxrwxrwx 1 root root 10816 Aug 24 17:58 write-records
-rwxrwxrwx 1 root root 2632 Aug 24 17:57 write-records.o

-rwxrwxrwx 1 root root 2081 Aug 24 17:57 write-records.s*
root@LAPTOP-5PGRQ2IO:/mnt/d/Projects/AssemblyProjects# ./helloworld-lib
-bash: ./helloworld-lib: No such file or directory
在执行 ./helloworld-lib 命令时提示 -bash: ./helloworld-lib: No such file or directory,但 helloworld-lib 实际上是存在的。

原因分析

/lib/ld-linux.so.2用于32位可执行文件,本人的系统是64位的WSL Ubuntu22.04,查看该文件是否存在:

ls /lib/ld-linux.so.2

ls: cannot access '/lib/ld-linux.so.2': No such file or directory
执行 ls /lib/ld-linux.so.2 命令可以发现系统中没有 /lib/ld-linux.so.2 这个文件,所以虽然执行ld命令时没有报错,但是执行 ./helloworld-lib 命令时报错了:-bash: ./helloworld-lib: No such file or directory。

解决方法

因为电脑是 64 位的,所以使用 /lib64/ld-linux-x86-64.so.2 而不是 /lib/ld-linux.so.2:

ld -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o helloworld-lib helloworld-lib.o -lc
二、英语总结
1.majorly
p129, Code that is copied often has to be majorly modified to fit the surrounding code.在这里,majorly既可以指“量”也可以指“质”上的巨大修改。

{spa.hb24718.com]
{spa.xibaihuo168.com]
{spa.myoulun.com]
{spa.songyuanit.com]
{spa.shangchengtao.com]
三、其它
上一次阅读还是2024/8/24,期间因为工作上一些不愉快的事一直没有抽离出来,今天算是慢慢调整过来了,继续干。

四、参考资料

  1. 编程
    (1)Jonathan Bartlett,《Programming From The Ground Up》:https://book.douban.com/subject/1787855/

  2. 英语
    (1)Etymology Dictionary:https://www.etymonline.com

(2) Cambridge Dictionary:https://dictionary.cambridge.org

相关文章
|
5月前
|
机器学习/深度学习 算法 图形学
【论文泛读】NeRF: Representing Scenes as Neural Radiance Fields for View Synthesis
【论文泛读】NeRF: Representing Scenes as Neural Radiance Fields for View Synthesis
|
机器学习/深度学习 自然语言处理 监控
Lecture 1:强化学习简介
Lecture 1:强化学习简介
|
机器学习/深度学习 编解码 数据可视化
《Progressive Growing of GANs for Improved Quality, Stability, and Variation》-论文阅读笔记(三)
《Progressive Growing of GANs for Improved Quality, Stability, and Variation》-论文阅读笔记(三)
83 0
《Progressive Growing of GANs for Improved Quality, Stability, and Variation》-论文阅读笔记(三)
|
机器学习/深度学习 编解码
《Progressive Growing of GANs for Improved Quality, Stability, and Variation》-论文阅读笔记(二)
《Progressive Growing of GANs for Improved Quality, Stability, and Variation》-论文阅读笔记(二)
120 0
《Progressive Growing of GANs for Improved Quality, Stability, and Variation》-论文阅读笔记(二)
|
机器学习/深度学习
《Progressive Growing of GANs for Improved Quality, Stability, and Variation》-论文阅读笔记(一)
《Progressive Growing of GANs for Improved Quality, Stability, and Variation》-论文阅读笔记(一)
101 0
《Progressive Growing of GANs for Improved Quality, Stability, and Variation》-论文阅读笔记(一)
|
机器学习/深度学习 搜索推荐 算法
【推荐系统论文精读系列】(三)--Matrix Factorization Techniques For Recommender Systems
现在推荐系统一般是基于两种策略,一种是基于文本过滤的方式,另外一种是协同过滤,而基于文本过滤的方法是创造画像为用户或者物品,说白了就是用一些描述性的特征去描述它们,例如对于一部电影来说,可以为其创造画像电影类型、导演、演员、电影市场、票房等来进行描述,对于用户来说,可以用一些人口统计特征来进行描述。
464 1
|
机器学习/深度学习 人工智能 搜索推荐
【推荐系统论文精读系列】(十二)--Neural Factorization Machines for Sparse Predictive Analytics
现在很多基于网站应用的预测任务都需要对类别进行建模,例如用户的ID、性别和职业等。为了使用通常的机器学习预测算法,需要将这些类别变量通过one-hot将其转化成二值特征,这就会导致合成的特征向量是高度稀疏的。为了有效学习这些稀疏数据,关键就是要解释不同特征之间的影响。
369 0
|
机器学习/深度学习 搜索推荐
【推荐系统论文精读系列】(十四)--Information Fusion-Based Deep Neural Attentive Matrix Factorization Recommendation
推荐系统的出现,有效地缓解了信息过载的问题。而传统的推荐系统,要么忽略用户和物品的丰富属性信息,如用户的人口统计特征、物品的内容特征等,面对稀疏性问题,要么采用全连接网络连接特征信息,忽略不同属性信息之间的交互。本文提出了基于信息融合的深度神经注意矩阵分解(ifdnamf)推荐模型,该模型引入了用户和物品的特征信息,并采用不同信息域之间的交叉积来学习交叉特征。此外,还利用注意机制来区分不同交叉特征对预测结果的重要性。此外,ifdnamf采用深度神经网络来学习用户与项目之间的高阶交互。同时,作者在电影和图书这两个数据集上进行了广泛的实验,并证明了该模型的可行性和有效性。
283 0
【推荐系统论文精读系列】(十四)--Information Fusion-Based Deep Neural Attentive Matrix Factorization Recommendation
|
机器学习/深度学习 存储 搜索推荐
【推荐系统论文精读系列】(二)--Factorization Machines
本篇论文中,作者介绍了一个新的分解模型Fatorization Machines(FM),它结合了支持向量机的一些优点。与SVM一样,FM模型是一个通用的预测分类器适用于任何真实值的向量。但是与SVM不同的是,FM通过使用分解参数的方式在不同变量之间进行建模。
280 0
|
机器学习/深度学习 人工智能 搜索推荐
【推荐系统论文精读系列】(十一)--DeepFM A Factorization-Machine based Neural Network for CTR Prediction
在推荐系统领域最大化CTR最关键就是要学习用户举止背后复杂的特征交互。尽管现在已经有了一些大的进展,但是现存的方式仍然是只能捕捉低阶或者高阶特征,或者需要专业的特征工程。本篇论文中,我们提出了一种端到端的学习模型,能够同时学习到低阶和高阶的交互特征。我们将这个模型命名为DeepFM,它结合了分解机的能力和深度学习捕捉高阶特征的能力。对比最新谷歌提出的Wide & Deep模型,我们的DeepFM模型不需要任何特征工程,而且会共享特征输入。
249 0