在链接一些对类型long longI 的整数执行除法和模运算的代码时,会收到以下两个错误:
util.c:(.text+0x1af): undefined reference to '__divdi3'
util.c:(.text+0x1ef): undefined reference to '__moddi3'
Run Code Online (Sandbox Code Playgroud)
我也试过使用unsigned long long,但是会导致以下错误:
util.c:(.text+0x1af): undefined reference to '__udivdi3'
util.c:(.text+0x1ef): undefined reference to '__umoddi3'
Run Code Online (Sandbox Code Playgroud)
更换long long用int或long解决问题,但我需要使用unsigned long long.
我使用以下命令行来编译和链接程序:
gcc -ffreestanding -c kernel/util.c -o kernel/util.o
ld -o kernel32.bin -Ttext 0x500 kernel/util.o kernel/kernel.o --oformat binary
Run Code Online (Sandbox Code Playgroud)
这是功能:
char* itoa(unsigned long long i, char b[]){
if (i == 0){
b[0] = '0';
b[1] = '\0';
return b;
}
char …Run Code Online (Sandbox Code Playgroud) 为保护模式设置中断的过程是什么?
这个链接说应该:
- 为中断描述符表腾出空间
- 告诉CPU该空间在哪里(参见GDT教程:lidt的工作方式与lgdt完全相同)
- 告诉PIC您不再需要使用BIOS默认值(请参阅编程PIC芯片)
- 为IRQ和异常编写几个ISR处理程序(请参阅中断服务程序)
- 将ISR处理程序的地址放在适当的描述符中
- 启用IRQ掩码中所有支持的中断(PIC)
第三步对我来说毫无意义(我查看了这个链接,但没有任何关于告诉PIC的事情)所以我忽略了它并完成了接下来的两个步骤,当我到达最后一步时再次无能为力.但是,根据我对中断的理解,我不理解的两个步骤都与PIC控制器的硬件中断有关,不应该影响PIT在IRQ 0上引发的中断.因此我也忽略了这一步骤.
当我运行我的代码时,它编译得很好,甚至在虚拟机中运行,但中断似乎只发射一次.然后我意识到我没有向EOI发送EOI,以防止它再引发任何中断.但是,添加mov al, 0x20并out 0x20, al在iret指令之前使虚拟机崩溃.
这是我的IDT:
; idt
idt_start :
dw 0x00 ; The interrupt handler is located at absolute address 0x00
dw CODE_SEG ; CODE_SEG points to the GDT entry for code
db 0x0 ; The unused byte
db 0b11101001 ; 1110 Defines a 32 bit Interrupt gate, 0 is mandatory, privilege level = 0 (0b00), the last bit is …Run Code Online (Sandbox Code Playgroud) 什么是最有效的内存算法,可用于查找从一个网格到另一个网格的路径?网格可能有无法跨越的障碍物.作为最短的路径是没有必要的,但肯定是一个奖励.该算法将用C语言编写(C++可用,但我避免使用它来减少内存使用)并运行在只有2048字节SRAM的ATmega328芯片上.CPU效率不是最重要的.
编辑:网格是16乘32个正方形,每个正方形由一位表示.因此,总内存使用量为64字节.网格存储为无符号字符的2D数组,并且所有2048字节都可用.输出将是一个引用应该采用的正方形的整数数组.
如果正方形中存在障碍物,则正方形阵列将具有1而不是零.这些方块应该像墙一样处理.
我在阅读 MSVC STL 实现std::ranges::remove时注意到以下行:
_First = _RANGES _Find_if_unchecked(_STD move(_First), _Last, _Pred, _Proj);
Run Code Online (Sandbox Code Playgroud)
事实上,cppreference在其“可能的实现”中也有以下行:
first = ranges::find_if(std::move(first), last, pred, proj);
Run Code Online (Sandbox Code Playgroud)
让我感到困惑的是,我几乎从未见过有人移动迭代器;它们通常复制起来很便宜(或者至少应该如此),即使这是复制的问题,我们肯定可以采用通用引用和std::forward迭代器find_if来代替吗?
与简单地按值传递相比,强制转换为右值引用有什么优势?
我正在使用Visual Studio 2013为AVR编写代码.我一直在关注这个教程.
在编写代码的同时,我注意到Visual Studio继续强调像DDRB或者这样的东西,PORTB并且我继续得到错误Error: identifier "PORTB" is undefined,但是,程序正确编译.
有趣的是,在按下alt- F12视觉发现它们被定义了许多文件.
如果我有以下代码:
void bar(){
int x = 1;
foo();
}
void foo(){
while(true);
}
Run Code Online (Sandbox Code Playgroud)
调用when时int x使用的内存会发生什么变化?它被释放了吗?我知道如果函数返回则释放内存,但是在这种情况下函数根本不会返回.bar()foo()
如果我使用这个代码,其中bar调用foo,反过来,调用bar等等,程序最终会耗尽内存,还是新的函数实例会被新代码替换?
void bar(){
int x = 1;
foo();
}
void foo(){
int y = 1;
bar();
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试制作可以改变颜色的div.这是我的代码:
window.onload = function () {
for (;;){
setTimeout(function () {
document.querySelector('style').style.backgroundColor = colors[rand(colors.length)];
}, 2000);
}
}
var colors = [
'red',
'green',
'blue',
'yellow',
'magenta',
'pink'
];
var rand = function (max) {
return Math.floor(Math.random() * max);
};Run Code Online (Sandbox Code Playgroud)
.style{
background-color: pink;
top: 50px;
left: 50px;
height: 50px;
width: 50px;
}Run Code Online (Sandbox Code Playgroud)
<body>
<div class="style"></div>
</body>Run Code Online (Sandbox Code Playgroud)
但我无法找出它为什么不起作用.
编辑:该脚本也崩溃了浏览器
在 C++20 中,我们可以分配内存constexpr只要在上下文 \xe2\x80\x94 中释放内存,我们就可以在上下文中分配内存,即这是有效的:
constexpr int* g(){\n int* p = new int(100);\n return p;\n}\n\nconstexpr int f(){\n int* ret = g();\n int i = *ret;\n delete ret;\n return i;\n}\nstatic_assert(f() == 100);\nRun Code Online (Sandbox Code Playgroud)\n然而这不会编译:
\nconstexpr int* g(){\n int* p = new int(100);\n return p;\n}\n\nconstexpr int f(){\n int* ret = g();\n int i = *ret;\n return i;\n}\nstatic_assert(f() == 100);\nRun Code Online (Sandbox Code Playgroud)\n出现错误:
\nerror: '(f() == 100)' is not a constant expression because allocated storage has not been deallocated\n …Run Code Online (Sandbox Code Playgroud) c ×4
c++ ×3
c++20 ×2
memory ×2
algorithm ×1
assembly ×1
avr ×1
html ×1
ide ×1
intellisense ×1
interrupt ×1
javascript ×1
linker ×1
memory-leaks ×1
performance ×1
std ×1
winavr ×1
x86 ×1