编写一个masm程序,生成两个随机数 并比较大小,如果是大的 输出"im suprman" 小的 输出"im stupid"
时间: 2024-02-05 09:11:03 浏览: 25
以下是一个使用MASM汇编语言编写的程序,它可以生成两个随机数,并比较它们的大小,根据比较结果输出不同的消息。请注意,这个程序使用了Windows API函数,所以需要在Windows操作系统上运行。
```
.386
.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
.data
message1 db "im suprman", 0
message2 db "im stupid", 0
.code
start:
; 初始化随机数生成器
invoke GetTickCount
invoke srand, eax
; 生成两个随机数
invoke rand
mov ebx, eax
invoke rand
mov ecx, eax
; 比较两个随机数
cmp ebx, ecx
jg greater
jl lesser
; 如果两个随机数相等,则输出错误信息
invoke MessageBox, NULL, addr message2, NULL, MB_OK
jmp exit
greater:
; 输出im suprman
invoke MessageBox, NULL, addr message1, NULL, MB_OK
jmp exit
lesser:
; 输出im stupid
invoke MessageBox, NULL, addr message2, NULL, MB_OK
jmp exit
exit:
invoke ExitProcess, 0
end start
```