《Programming from the Ground Up》阅读笔记:p49-p74

news/2024/9/13 11:36:51/文章来源:https://www.cnblogs.com/codists/p/18304407

《Programming from the Ground Up》学习第3天,p49-p74总结,总计26页。

一、技术总结

1.function

(1)定义

p49, Functions are unit of code that do a defined piece of work on specified types of data。

函数是在指定类型的数据上完成所定义的某个工作的代码单元。

(2)parameter

p49, The data items a function is given to process are called it's parameters。

给予函数处理的数据项称为函数的参数。

(3)interface

p49, The parameter list and the processing expectations of a function(what it is expected to to with the parameters) are called the function's interface。

函数参数列表和预期处理结果称为函数的接口。

2.primitive functions/primitives

p50,However, ultimately there are things that you cannot write functions for which must be provided by the system. Those are called primiteive function(or just primiteives)-they are teh basics which everything else is built off of.

这些由系统提供的函数称为原函数(或原语)。

3.stack

(1)定义

p51,Each computer program that runs uses a region of memory called the stack to enable functions to work properly.

The computer's stack lives at the very top address of memory.

stack(栈)就是memory(内存)的一块区域,位于内存的最顶端。这是物理意义的上的。

4.power.s

#PURPOSE: Program to illustrate how functions work
#         This program will compute the value of
#         2^3 + 5^2
##Everything in the main program is stored in registers,
#so the data section doesn't have anything.section .data #.data的作用是什么?.section .text #.text的作用是什么?.global _start
_start:pushq $3 #push second argumentpushq $2 #push first argumentcall power # call the functionadd $8, %rsp #movqe the stack pointer backpushq %rax #save the first answer before#calling the next functionpushq $2 #push second argumentpushq $5call power #call the functionadd $8, %rsp #movqe the stack pointer backpopq %rbx #The second answer is already #in %rax. We save the  #first answer onto the stack, #so now we can just pop it #out into %rbxadd %rax, %rbx #add them together#the result is in %rbxmovq $1, %rax #exit (%rbx is returned)int $0x80#PURPOSE: This function is used to compute
#the value of a number raised to a power.
#
#INPUT: First argument-the base number
#Second argument-the power to raise it to
#
#OUTPUT: Will give the result as a return value
#
#NOTES: The power must be 1 or greater
#
#VARIABLES: 
#%rbx - holds the base number
#%rcx - holds the power
#
#-4(%rbp) - holds the current result
#
# %rax is used for temporary storage
#.type power, @function
power:pushq %rbp #save old base pointermovq %rsp, %rbp # make stack pointer the base pointersub $4, %rsp #get room for our local storagemovq 8(%rbp), %rbx #put first argument in %raxmovq 12(%rbp), %rcx #put second argument in %rcxmovq %rbx, -4(%rbp) #store current resultpower_loop_start:cmp $1, %rcx #if the power is 1, we are doneje end_powermovq -4(%rbp), %rax #movqe the current result into %raximul %rbx, %rax #multiply the current result by #the base numbermovq %rax, -4(%rbp) #store the current resultdec %rcx #decrease the powerjmp power_loop_start # run for the next powerend_power:movq -4(%rbp), %rax # return value goes in %raxmovq %rbp, %rsp #restore the stack pointerpopq %rbp #restore the base pointerret   

书里使用的是32位的电脑,但我们现在的电脑大多是64位的,如果运行书中的代码就会提示:Error: invalid instruction suffix for `push',这里对代码做了修改,改为64位电脑里的寄存器。

二、英语总结

无。

三、其它

1.8、16、32、64位电脑里寄存器的名字

因为不同教材使用的寄存器名称不一样,容易对初学者造成困扰,这里把8位、16位、32位、64位电脑里的寄存器名称全部列出来,这样在看到这些名字的时候我们就知道作者使用的是多少位的电脑。同时我们尽量在对应位数的电脑里去运行这些代码。

r8 = AL AH BL BH CL CH DL DH

r16 = AX BX CX DX BP SP SI DI

r32 = EAX EBX ECX EDX EBP ESP ESI EDI

r64 = RAX RBX RCX RDX RBP RSP RSI RDI R8 R9 R10 R11 R12 R13 R14 R15

2.32和64位电脑里寄存器调用区别

(1)x86 Assembly pushl/popl don't work with "Error: suffix or operands invalid"

https://stackoverflow.com/questions/5485468/x86-assembly-pushl-popl-dont-work-with-error-suffix-or-operands-invalid

(2)What are the calling conventions for UNIX & Linux system calls (and user-space functions) on i386 and x86-64

https://stackoverflow.com/questions/2535989/what-are-the-calling-conventions-for-unix-linux-system-calls-and-user-space-f

四、参考资料

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

欢迎搜索及关注:编程人(a_codists)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/744485.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

关于css选择器和样式表的应用

我已经将 #usual-links.card {background-color: red; }复制到样式表index.css,并且已经在模板中引入样式表,如:<!--最后引入自定义的css。因为引入css的顺序会影响相同元素的样式呈现--><link rel="stylesheet" href="{% static css/index.css %}&…

IEC104初学者教程,第四章:IEC 104 开发环境搭建

第四章:IEC 104 开发环境搭建 目录第四章:IEC 104 开发环境搭建IEC104从站模拟器的使用IEC104主站模拟器的使用 为了搭建开发环境,我们需要准备三款软件:主站下载地址:IEC104主站模拟器 从站下载地址:IEC104从站模拟器IEC104主站模拟器代表主站(客户端、上位机)负责和从…

nginx小经验:nginx: worker process is shutting down

民间艺术团保安队副队长关注IP属地: 北京 2022.12.14 15:34:14字数 80阅读 1,038 image.png如上图所示:nginx -s reload 之后,新的请求已不会往老的进程转发,一直有连接未断开的老进程一直已“nginx: worker process is shutting down”状态存在 解决办法:1、手动杀掉进程2…

【C++】map

1、定义 template<class Key,class T,class Compare = std::less<Key>,class Allocator = std::allocator<std::pair<const Key, T>> > class map;namespace pmr {template<class Key,class T,class Compare = std::less<Key>> using map …

读人工智能全传14有意识的机器之路

读人工智能全传14有意识的机器之路1. 有意识的机器之路 1.1. 近年来人工智能和深度学习方面取得了真实的、令人兴奋的突破,但它们并不是构建通用人工智能的法宝 1.2. 深度学习可能是通用人工智能的一个重要组成部分,但它绝不是唯一的组成部分 1.3. …

[BSidesCF 2019]SVGMagic 1

SVG注入 xxe攻击打开后发发现他是SVG上传,在这之前我没有接触过SVG是什么,先去学习了一下发现他是xml注入的一种方法,也是通过js代码实现文件读取的 这是几个我看的关于svg的文章 https://www.freebuf.com/vuls/175451.html https://blog.csdn.net/gxyzlxf/article/details/…

【C++】创建对象写法

1、在栈中创建对象 栈中创建的对象,不用我们手动释放资源。 和创建基本类型一样,直接声明即可,如果有参数,则用括号。 vector<int> a; // 默认构造函数 vector<int> b(实参); // 其他构造函数2、在堆中创建对象 堆中创建的对象,需要我们手动释放资源。 使用ne…

PostgreSQL 工具及mysql、mongo

pgAdmin 开源管理工具,提供强大的图形界面,简化数据库对象的创建、维护和使用。 Percona 监控和管理工具 通过单一窗口轻松查看和监控 MySQL、MongoDB、PostgreSQL 和 MariaDB 数据库的性能。 安装PMM服务器curl -fsSL https://www.percona.com/get/pmm | /bin/bash下载PMM …

SciTech-EECS-Wireless-BLE(Bluetooth Low Energy)5.4- Nordic Semi. 的Bluetooth Low Energy SoCs

蓝牙5.4低功耗: 市场上主流的供货方和解决方案:TI Nordic Semi. : nRF5340, nrf52*,Best-in-class Bluetooth Low Energy SoCs Bluetooth Low Energy flagship SoC The nRF5340 SoC is our Bluetooth Low Energy flagship. It is the first SoC in the nRF53 Series and is the…

全网最适合入门的面向对象编程教程:17 类和对象的Python实现-鸭子类型与“file-like object“

本文主要介绍了Python中创建自定义类时鸭子类型的基本定义、特点和应用场景,同时列举了“file-like object“的例子对鸭子类型进行了说明。全网最适合入门的面向对象编程教程:17 类和对象的 Python 实现-鸭子类型与“file-like object“ 摘要: 本文主要介绍了 Python 中创建…

【C++】使用ort推理yolov10

【C++】使用ort推理yolov10 前言:由于笔者是编导专业,想玩玩yolo模型,搜来搜去全是python,所以在学会之后写一篇文章帮助和笔者同样情况的人 环境 Windows 10 C++17 onnxruntime18.1(DML版本) opencv4.9 visual studio2022 1. 环境配置 1.1 OpenCV环境配置 1.1.1 OpenCV …

使用FModel提取游戏资产

介绍使用FModel提取游戏资产的过程目录前言FModel简介FModel安装FModel使用初次使用资产预览资产导出附录dumperDumper-7生成usmap文件向游戏中注入dll 前言 这篇文章仅记录我作为初学者使用FModel工具提取某款游戏模型的过程。 FModel简介 FModel是一个开源软件,可以用于查看…