-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
220 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
44 | ||
3 | ||
.text,0x400000,5,32 | ||
.data,0x400800,37,3 | ||
.symtab,0x0,40,4 | ||
push %rbp | ||
mov %rsp,%rbp | ||
sub $0x10,%rsp | ||
mov $0x2,%esi | ||
lea 0x0000000000000948(%rip),%rdi | ||
callq 0x0000000000000160 | ||
mov %rax,-0x8(%rbp) | ||
mov -0x8(%rbp),%rax | ||
leaveq | ||
retq | ||
push %rbp | ||
mov %rsp,%rbp | ||
mov %rdi,-0x18(%rbp) | ||
mov %rsi,-0x20(%rbp) | ||
movq $0x0,-0x8(%rbp) | ||
movq $0x0,-0x10(%rbp) | ||
jmp 3d | ||
mov -0x10(%rbp),%rax | ||
lea 0x0(,%rax,8),%rdx | ||
mov -0x18(%rbp),%rax | ||
add %rdx,%rax | ||
mov (%rax),%rax | ||
add %rax,-0x8(%rbp) | ||
addq $0x1,-0x10(%rbp) | ||
mov -0x10(%rbp),%rax | ||
cmp -0x20(%rbp),%rax | ||
jb 1e | ||
mov 0x0000000000000170(%rip),%rdx | ||
mov -0x8(%rbp),%rax | ||
add %rdx,%rax | ||
pop %rbp | ||
retq | ||
0x0000000012340000 | ||
0x000000000000abcd | ||
0x0000000f00000000 | ||
main,STB_GLOBAL,STT_FUNC,.text,0,10 | ||
sum,STB_GLOBAL,STT_FUNC,.text,10,22 | ||
array,STB_GLOBAL,STT_OBJECT,.data,0,2 | ||
bias,STB_GLOBAL,STT_OBJECT,.data,2,1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* BCST - Introduction to Computer Systems | ||
* Author: yangminz@outlook.com | ||
* Github: https://github.com/yangminz/bcst_csapp | ||
* Bilibili: https://space.bilibili.com/4564101 | ||
* Zhihu: https://www.zhihu.com/people/zhao-yang-min | ||
* This project (code repository and videos) is exclusively owned by yangminz | ||
* and shall not be used for commercial and profitting purpose | ||
* without yangminz's permission. | ||
*/ | ||
|
||
// include guards to prevent double declaration of any identifiers | ||
// such as types, enums and static variables | ||
#ifndef INSTRUCTION_GUARD | ||
#define INSTRUCTION_GUARD | ||
|
||
#include <stdint.h> | ||
|
||
/*======================================*/ | ||
/* instruction set architecture */ | ||
/*======================================*/ | ||
|
||
// data structures | ||
typedef enum INST_OPERATOR | ||
{ | ||
INST_MOV, // 0 | ||
INST_PUSH, // 1 | ||
INST_POP, // 2 | ||
INST_LEAVE, // 3 | ||
INST_CALL, // 4 | ||
INST_RET, // 5 | ||
INST_ADD, // 6 | ||
INST_SUB, // 7 | ||
INST_CMP, // 8 | ||
INST_JNE, // 9 | ||
INST_JMP, // 10 | ||
} op_t; | ||
|
||
typedef enum OPERAND_TYPE | ||
{ | ||
EMPTY, // 0 | ||
IMM, // 1 | ||
REG, // 2 | ||
MEM_IMM, // 3 | ||
MEM_REG1, // 4 | ||
MEM_IMM_REG1, // 5 | ||
MEM_REG1_REG2, // 6 | ||
MEM_IMM_REG1_REG2, // 7 | ||
MEM_REG2_SCAL, // 8 | ||
MEM_IMM_REG2_SCAL, // 9 | ||
MEM_REG1_REG2_SCAL, // 10 | ||
MEM_IMM_REG1_REG2_SCAL // 11 | ||
} od_type_t; | ||
|
||
typedef struct OPERAND_STRUCT | ||
{ | ||
od_type_t type; // IMM, REG, MEM | ||
uint64_t imm; // immediate number | ||
uint64_t scal; // scale number to register 2 | ||
uint64_t reg1; // main register | ||
uint64_t reg2; // register 2 | ||
} od_t; | ||
|
||
// local variables are allocated in stack in run-time | ||
// we don't consider local STATIC variables | ||
// ref: Computer Systems: A Programmer's Perspective 3rd | ||
// Chapter 7 Linking: 7.5 Symbols and Symbol Tables | ||
typedef struct INST_STRUCT | ||
{ | ||
op_t op; // enum of operators. e.g. mov, call, etc. | ||
od_t src; // operand src of instruction | ||
od_t dst; // operand dst of instruction | ||
} inst_t; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.