ver 0.3

前言
前面文章已经介绍了CPU的基础概念,为我们进一步研究虚拟化技术的一个最重要分支vCPU奠定了基础。回顾前文,我们知道一个CPU-Core的最根本任务就是执行指令,包括取指-执行-访存-回写,如图1-1所示。

为什么要了解和学习指令集(ISA),先看一段ARM官方的说法
Why you should care about the ISA
As developers, you may not need to write directly in assembler in our day-to-day role. However, assembler is still important in some areas, such as the first stage boot software or some low-level kernel activities.
Even if you are not writing assembly code directly, understanding what the instruction set can do, and how the compiler makes use of those instructions, can help you to write more efficient code. It can also help you to understand the output of the compiler. This can be useful when debugging.
对于一名辛勤搞虚拟化开发的码农来说,虚拟化相关的代码主要由3部分组成:Hypervisor、VM、GuestOS。要写出高效的,性能良好的虚拟化代码,也一定要了解到底什么是ISA。
指令集对于CPU就是一串机器码表征的高低电平信号,对于程序员来说就是相对比较友好的汇编指令集合。先看两段代码让大家有一个直观的感受。
test.c语言代码:
#include <stdio.h>
#include <string.h>
static char *TAG = "[TEST]";
int add(int a, int b)
{
return a+b;
}
int main(void)
{
int para1 = 1, para2 = 2;
int result;
result = add(para1, para2);
printf(" %s %s --in--\n", TAG, __func__);
return 0;
}
test.c对应的test.s汇编代码:
.arch armv8-a
.file "test.c"
.text
.section .rodata
.align 3
.LC0:
.string "[TEST]"
.data
.align 3
.type TAG, %object
.size TAG, 8
TAG:
.xword .LC0
.text
.align 2
.global add
.type add, %function
add:
.LFB0:
.cfi_startproc
sub sp, sp, #16
.cfi_def_cfa_offset 16
str w0, [sp, 12]
str w1, [sp, 8]
ldr w1, [sp, 12]
ldr w0, [sp, 8]
add w0, w1, w0
add sp, sp, 16
.cfi_def_cfa_offset 0
ret
.cfi_endproc
.LFE0:
.size add, .-add

最低0.47元/天 解锁文章
2628

被折叠的 条评论
为什么被折叠?



