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

《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 argument
 pushq $2 #push first argument
 call power # call the function
 add $8, %rsp #movqe the stack pointer back
 
 pushq %rax #save the first answer before
            #calling the next function

 pushq $2 #push second argument
 pushq $5
 call power #call the function
 add $8, %rsp #movqe the stack pointer back
 
 popq %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 %rbx
 
 add %rax, %rbx #add them together
                 #the result is in %rbx
				 
 movq $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 pointer
 movq %rsp, %rbp # make stack pointer the base pointer
 sub $4, %rsp #get room for our local storage
 
 movq 8(%rbp), %rbx #put first argument in %rax
 movq 12(%rbp), %rcx #put second argument in %rcx
 movq %rbx, -4(%rbp) #store current result
 
 power_loop_start:
  cmp $1, %rcx #if the power is 1, we are done
  je end_power
  movq -4(%rbp), %rax #movqe the current result into %rax
  imul %rbx, %rax #multiply the current result by 
                   #the base number
  movq %rax, -4(%rbp) #store the current result
  
  
  dec %rcx #decrease the power
  jmp power_loop_start # run for the next power
  
  end_power:
   movq -4(%rbp), %rax # return value goes in %rax
   movq %rbp, %rsp #restore the stack pointer
   popq %rbp #restore the base pointer
   ret   
 

书里使用的是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)

数据集介绍:电力线目标检测数据集 一、基础信息 数据集名称:电力线目标检测数据集 图片数量: 训练集:2898张图片 验证集:263张图片 测试集:138张图片 总计:3299张图片 分类类别: 类别ID: 0(电力线) 标注格式: YOLO格式,包含对象标注信息,适用于目标检测任务。 数据格式:JPEG/PNG图片,来源于空中拍摄或监控视觉。 二、适用场景 电力设施监控与巡检: 数据集支持目标检测任务,帮助构建能够自动识别和定位电力线的AI模型,用于无机或固定摄像头巡检,提升电力设施维护效率和安全性。 能源与公用事业管理: 集成至能源管理系统中,提供实时电力线检测功能,辅助进行风险 assessment 和预防性维护,优化能源分配。 计算机视觉算法研究: 支持目标检测技术在特定领域的应用研究,促进AI在能源和公用事业行业的创新与发展。 专业培训与教育: 数据集可用于电力行业培训课程,作为工程师和技术员学习电力线检测与识别的重要资源。 三、数据集优势 标注精准可靠: 每张图片均经过专业标注,确保电力线对象的定位准确,适用于高精度模型训练。 数据多样性丰富: 包含多种环境下的电力线图片,如空中视角,覆盖不同场景条件,提升模型的泛化能力和鲁棒性。 任务适配性强: 标注格式兼容YOLO等主流深度学习框架,便于快速集成和模型开发,支持目标检测任务的直接应用。 实用价值突出: 专注于电力线检测,为智能电网、自动化巡检和能源设施监控提供关键数据支撑,具有较高的行业应用价值。
【弹簧阻尼器】基于卡尔曼滤波弹簧质量阻尼器系统噪声测量实时状态估计研究(Matlab代码实现)内容概要:本文围绕“基于卡尔曼滤波的弹簧质量阻尼器系统噪声测量与实时状态估计”展开研究,利用Matlab代码实现对系统状态的精确估计。重点在于应用卡尔曼滤波技术处理系统中存在的噪声干扰,提升对弹簧质量阻尼器系统动态行为的实时观测能力。文中详细阐述了系统建模、噪声特性分析及卡尔曼滤波算法的设计与实现过程,展示了滤波算法在抑制测量噪声、提高状态估计精度方面的有效性。同时,该研究属于更广泛的信号处理与状态估计技术应用范畴,适用于复杂动态系统的监控与控制。; 适合群:具备一定控制系统理论基础和Matlab编程经验的高校研究生、科研员及工程技术员,尤其适合从事动态系统建模、状态估计与滤波算法研究的相关员。; 使用场景及目标:①应用于机械、航空航天、自动化等领域中对振动系统状态的高精度实时估计;②为噪声环境下的传感器数据融合与状态预测提供算法支持;③作为卡尔曼滤波算法在实际物理系统中应用的教学与科研案例。; 阅读建议:建议读者结合Matlab代码实践,深入理解系统建模与滤波器设计的关键步骤,关注噪声建模与滤波参数调优对估计性能的影响,并可进一步拓展至扩展卡尔曼滤波(EKF)或无迹卡尔曼滤波(UKF)在非线性系统中的应用。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值