xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

Linux 内存地址为何是从 0x7c00 开始 All In One

Linux 内存地址为何是从 0x7c00 开始 All In One

image

image

assembly language

.asm


image

https://en.wikipedia.org/wiki/Assembly_language

https://zh.wikipedia.org/wiki/汇编语言

汇编语言(第4版) 王爽

https://www.worldcat.org/zh-cn/formats-editions/910380574

http://www.tup.tsinghua.edu.cn/wap/tsxqy.aspx?id=07970801

汇编语言 => 编译器 => 机器码

汇编指令、伪指令、助记符、运算符号

image

pdf 安全:DOM 蒙层 & js 禁用复制

https://wqbook.wqxuetang.com/deep/read/pdf?bid=3213288

image

汇编语言教程


/**
 *
 * @author xgqfrms
 * @license MIT
 * @copyright xgqfrms
 * @created 2023-01-30
 * @modified
 *
 * @description C 语言 & 汇编语言
 * @difficulty Easy
 * @complexity O(n)
 * @augments
 * @example
 *
 * @link https://www.cnblogs.com/xgqfrms/p/17074352.html
 * @link https://www.ruanyifeng.com/blog/2018/01/assembly-language-primer.html
 *
 * @solutions
 *
 */

#include <stdio.h>

int add(int a, int b) {
  return a + b;
}

int main() {
  // printf("Hello, World!\n");
  // printf("Hello, Assembly Language!\n");
  int sum = add(1, 2);
  printf("sum = %i", sum);
  // fix: `sum = 3%` bug ❌
  printf("\n");
  return 0;
}

/*

$ gcc ./add.c
# 二合一
$ gcc ./add.c -o add.out && ./add.out
# sum = 3 ✅

 */

/*

# 使用 gcc 把 `C 语言`程序转换成`汇编语言`程序
$ gcc -S ./add.c

# 二合一
$ gcc -S ./add.c && ./add.s

 */


  .section	__TEXT,__text,regular,pure_instructions
  .build_version macos, 13, 0	sdk_version 13, 1
  .globl	_add                            ## -- Begin function add
  .p2align	4, 0x90
_add:                                   ## @add
  .cfi_startproc
## %bb.0:
  pushq	%rbp
  .cfi_def_cfa_offset 16
  .cfi_offset %rbp, -16
  movq	%rsp, %rbp
  .cfi_def_cfa_register %rbp
  movl	%edi, -4(%rbp)
  movl	%esi, -8(%rbp)
  movl	-4(%rbp), %eax
  addl	-8(%rbp), %eax
  popq	%rbp
  retq
  .cfi_endproc
                                        ## -- End function
  .globl	_main                           ## -- Begin function main
  .p2align	4, 0x90
_main:                                  ## @main
  .cfi_startproc
## %bb.0:
  pushq	%rbp
  .cfi_def_cfa_offset 16
  .cfi_offset %rbp, -16
  movq	%rsp, %rbp
  .cfi_def_cfa_register %rbp
  subq	$16, %rsp
  movl	$0, -4(%rbp)
  movl	$1, %edi
  movl	$2, %esi
  callq	_add
  movl	%eax, -8(%rbp)
  movl	-8(%rbp), %esi
  leaq	L_.str(%rip), %rdi
  movb	$0, %al
  callq	_printf
  leaq	L_.str.1(%rip), %rdi
  movb	$0, %al
  callq	_printf
  xorl	%eax, %eax
  addq	$16, %rsp
  popq	%rbp
  retq
  .cfi_endproc
                                        ## -- End function
  .section	__TEXT,__cstring,cstring_literals
L_.str:                                 ## @.str
  .asciz	"sum = %i"

L_.str.1:                               ## @.str.1
  .asciz	"\n"

.subsections_via_symbols


http://www.ruanyifeng.com/blog/2018/01/assembly-language-primer.html

image

- A 1000:0
- MOV AX,4E20
- ADD AX,1416
- MOV BX,2000
- ADD AX,BX
- MOV BX,AX
- ADD AX,BX
- MOV AX,001A
- MOV BX,0026
- ADD AL,BL
- ADD AH,BL
- ADD BH,AL
- MOV AH,0
- ADD AL,BL
- ADD AL,9C

https://www.cnblogs.com/chantmee/p/14386408.html

https://www.ibm.com/docs/en/zos/2.1.0?topic=introduction-assembler-language

http://www.ece.utep.edu/courses/web3376/Notes_files/ee3376-assembly.pdf

https://www.w3cschool.cn/assembly/

X86 and X86_64 Assembly

; * @copyright xgqfrms
; * @created 2023-01-30

; https://www.tutorialspoint.com/assembly_programming/assembly_basic_syntax.htm

;Syntax of Assembly Language Statements
;[label]   mnemonic   [operands]   [;comment]

; INC COUNT        ; Increment the memory variable COUNT

; MOV TOTAL, 48    ; Transfer the value 48 in the
;                  ; memory variable TOTAL

; ADD AH, BH       ; Add the content of the
;                  ; BH register into the AH register

; AND MASK1, 128   ; Perform AND operation on the
;                  ; variable MASK1 and 128

; ADD MARKS, 10    ; Add 10 to the variable MARKS
; MOV AL, 10       ; Transfer the value 10 to the AL register

section	.text
   global _start     ;must be declared for linker (ld)

_start:	            ;tells linker entry point
   mov	edx,len     ;message length
   mov	ecx,msg     ;message to write
   mov	ebx,1       ;file descriptor (stdout)
   mov	eax,4       ;system call number (sys_write)
   int	0x80        ;call kernel

   mov	eax,1       ;system call number (sys_exit)
   int	0x80        ;call kernel

section	.data
msg db 'Hello, X86 Assembly!', 0xa  ;string to be printed
len equ $ - msg     ;length of the string



; assemble
; $ nasm -f elf hello.asm
; link
; $ ld -m elf_i386 -s -o hello hello.o
; execute
; $ ./hello

; X86 and X86_64 注释 `;`

ARM Assembly

@  * @copyright xgqfrms
@  * @created 2023-01-30

@  https://www.tutorialspoint.com/assembly_programming/assembly_basic_syntax.htm

@ Syntax of Assembly Language Statements
@ [label]   mnemonic   [operands]   [;comment]

@ INC COUNT        ; Increment the memory variable COUNT

@ MOV TOTAL, 48    ; Transfer the value 48 in the
@                  ; memory variable TOTAL

@ ADD AH, BH       ; Add the content of the
@                  ; BH register into the AH register

@ AND MASK1, 128   ; Perform AND operation on the
@                  ; variable MASK1 and 128

@ ADD MARKS, 10    ; Add 10 to the variable MARKS
@ MOV AL, 10       ; Transfer the value 10 to the AL register

section	.text
   global _start     ;must be declared for linker (ld)

_start:	            ;tells linker entry point
   mov	edx,len     ;message length
   mov	ecx,msg     ;message to write
   mov	ebx,1       ;file descriptor (stdout)
   mov	eax,4       ;system call number (sys_write)
   int	0x80        ;call kernel

   mov	eax,1       ;system call number (sys_exit)
   int	0x80        ;call kernel

section	.data
msg db 'Hello, ARM Assembly!', 0xa  ;string to be printed
len equ $ - msg     ;length of the string



@ assemble
@ $ nasm -f elf hello.asm
@ link
@ $ ld -m elf_i386 -s -o hello hello.o
@ execute
@ $ ./hello

@ ARM 注释 `@`


https://www.tutorialspoint.com/assembly_programming/index.htm

https://www.tutorialspoint.com/assembly_programming/assembly_basic_syntax.htm

Assembly REPL

https://www.tutorialspoint.com/compile_asm_online.php

NASM

https://www.nasm.us/

https://github.com/netwide-assembler/nasm

WebAssembly Language

.wasm

//

const importObject = { imports: { imported_func: (arg) => console.log(arg) } };

WebAssembly.instantiateStreaming(fetch("simple.wasm"), importObject).then(
  (obj) => obj.instance.exports.exported_func()
);

https://webassembly.org/

https://developer.mozilla.org/en-US/docs/WebAssembly

(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!

refs

Linux 0.11 源码趣读

https://time.geekbang.org/column/article/598506

https://time.geekbang.org/column/article/598511

为什么 X86 主引导记录的内存地址0x7C00

http://www.ruanyifeng.com/blog/2015/09/0x7c00.html

https://www.glamenv-septzen.net/en/view/6



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2023-01-30 09:24  xgqfrms  阅读(68)  评论(2编辑  收藏  举报