我已经看到这个问题了很多但从未见过真正的具体答案.所以我将在这里发布一个,希望能帮助人们理解为什么在使用随机数生成器时会出现"模数偏差",就像rand()在C++中一样.
此循环在英特尔Conroe/Merom上每3个周期运行一次,imul按预期方式在吞吐量方面存在瓶颈.但是在Haswell/Skylake上,它每11个循环运行一次,显然是因为setnz al它依赖于最后一个循环imul.
; synthetic micro-benchmark to test partial-register renaming
mov ecx, 1000000000
.loop: ; do{
imul eax, eax ; a dep chain with high latency but also high throughput
imul eax, eax
imul eax, eax
dec ecx ; set ZF, independent of old ZF. (Use sub ecx,1 on Silvermont/KNL or P4)
setnz al ; ****** Does this depend on RAX as well as ZF?
movzx eax, al
jnz .loop ; }while(ecx);
Run Code Online (Sandbox Code Playgroud)
如果setnz al …
我正在使用程序集8086emu,我需要一个用于8个数字的数字生成器。我试图通过@johnfound使用这段代码:
RANDGEN: ; generate a rand no using the system time
RANDSTART:
MOV AH, 00h ; interrupts to get system time
INT 1AH ; CX:DX now hold number of clock ticks since midnight
mov ax, dx
xor dx, dx
mov cx, 10
div cx ; here dx contains the remainder of the division - from 0 to 9
add dl, '0' ; to ascii from '0' to '9'
mov ah, 2h ; call interrupt to display a value in DL …Run Code Online (Sandbox Code Playgroud) 我有一个用于 MS-DOS 的 Hello, World 程序,它使用 int 21h 进行系统调用。
mov dx,hello
mov ah,9
int 0x21
mov ah,0
int 0x21
Run Code Online (Sandbox Code Playgroud)
“hello”是字符串“hello, world”,13,10,“$”的地址。
该程序有效。
然而,当我用“call 5”替换(第一个)“int 0x21”时,程序使计算机崩溃(即运行PTS-DOS的VirtualBox虚拟机)。在 DOSbox 上,它只是终止并返回到命令提示符。
我尝试使用不同的寄存器来存储地址和电话号码,但总是得到相同的结果。
现在我想知道...
有任何想法吗?
更新:我接受了答案,因为根据文档它是正确的。它仍然无法工作,但这可能是由于我的 DOS 版本或其他问题造成的。