小编Exc*_*_07的帖子

使用db在程序集NASM中声明一个字符串

我正在按照教程在汇编中编写一个hello world bootloader,我正在使用NASM汇编程序来安装x-86机器.这是我正在使用的代码:

[BITS 16]   ;Tells the assembler that its a 16 bit code
[ORG 0x7C00]    ;Origin, tell the assembler that where the code will
            ;be in memory after it is been loaded

MOV SI, HelloString ;Store string pointer to SI
CALL PrintString    ;Call print string procedure
JMP $       ;Infinite loop, hang it here.


PrintCharacter: ;Procedure to print character on screen
;Assume that ASCII value is in register AL
MOV AH, 0x0E    ;Tell BIOS that we need to print one …
Run Code Online (Sandbox Code Playgroud)

string x86 assembly nasm bootloader

5
推荐指数
1
解决办法
3940
查看次数

堆栈上大小可变的数组

据我了解,在C和C ++中,我们创建在堆栈上大小在编译时已知的数据结构,并使用堆(malloc-free / new-delete)处理大小在编译时未知的数据,是在运行时决定的。为什么,我的g ++编译器允许我执行类似以下代码段的操作。

int main(void)
{
    int n ;
    cin >> n ; // get the size of array.
    int arr[n] ; // create a variable sized array.
    .... do other stuff ...
}
Run Code Online (Sandbox Code Playgroud)

具体来说,在数组的情况下:
数组在堆栈上分配了一个连续的内存块,并且在堆栈上上下都有变量,因此必须知道数组的大小,以便堆栈上数组上方的变量,数组本身以及堆栈上数组下方的变量都可以整齐地放入内存。那么如何在堆栈上实现可变大小的数组呢? 为什么甚至有必要?为什么我们不能仅将堆用于可变大小的缓冲区?

编辑:
我从评论中了解到,关于VLA是否为标准,C和C ++有不同的规则,而且尼尔·巴特沃思(Neil Butterworth)的评论指出,同时询问两种语言通常不是一个好主意。谢谢大家,因此我打算从问题中删除C标签,因为我打算主要询问C ++,这从代码片段语法可以明显看出。抱歉造成您的困惑,也感谢您的答复。

c++ arrays stack

0
推荐指数
1
解决办法
649
查看次数

标签 统计

arrays ×1

assembly ×1

bootloader ×1

c++ ×1

nasm ×1

stack ×1

string ×1

x86 ×1