您好,我正在尝试在c ++中显示带有内联ASM的640x480 BMP图像(16色位图),它必须与内联asm一起使用,因为这是一项家庭作业。我在汇编代码中有以下代码可以做到这一点:

cad db 'Error, file not found, press a key to finish.$'
filename db "C:\image.bmp"
handle dw ?
col dw 0
ren dw 479
col1 dw ?
ren1 dw ?
col2 dw ?
ren2 dw ?
buffer db ?
colo db ?

eti0:
mov ah,3dh
mov al,0
mov dx,offset filename
int 21h
jc err
mov handle,ax
mov cx,118d

eti1:
push cx
mov ah,3fh
mov bx,handle
mov dx,offset buffer
mov cx,1
int 21h
pop cx
loop eti1

mov ah,00h
mov al,18d
int 10h

eti2:
mov ah,3fh
mov bx,handle
mov dx,offset buffer
mov cx,1
int 21h
mov al,buffer
and al,11110000b
ror al,4
mov colo,al
mov ah,0ch
mov al,colo
mov cx,col
mov dx,ren
int 10h
mov al,buffer
and al,00001111b
mov colo,al
inc col
mov ah,0ch
mov al,colo
mov cx,col
mov dx,ren
int 10h
inc col
mov ah,0ch
mov al,colo
mov cx,col
mov dx,ren
int 10h
cmp col,639d
jbe eti2
mov col,0
dec ren
cmp ren,-1
jne eti2


现在将其放入内联ASM中,我尝试使用下一个代码:

#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#include<dos.h>
#include<stdlib.h>

void main(void)
{
clrscr();
unsigned char buffer,colo;
unsigned int handle,col=0,ren=479,col1,col2,ren2;
int filename=675892105109971031011104698109112;
asm{
    mov ah,3dh
    mov al,0
    mov dx,filename
    int 21h
    mov handle,ax
    mov cx,118d
}
cout<<"si mino1";
for(int i=118;i>0;i++){
    asm{
        mov ah,3fh
        mov bx,handle
        mov dx,offset buffer
        mov cx,1
        int 21h
    }
}
asm{
    mov ah,00h
    mov al,18d
    int 10h
}
cout<<"si mino2";
    eti2:
asm{
    mov ah,3fh
    mov bx,handle
    mov dx,offset buffer
    mov cx,1
    int 21h
    mov al,buffer
    and al,11110000b
    ror al,4
    mov colo,al
    mov ah,0ch
    mov al,colo
    mov cx,col
    mov dx,ren
    int 10h
    mov al,buffer
    and al,00001111b
    mov colo,al
    inc col
    mov ah,0ch
    mov al,colo
    mov cx,col
    mov dx,ren
    int 10h
    inc col
    mov ah,0ch
    mov al,colo
    mov cx,col
    mov dx,ren
    int 10h
    cmp col,639d
    jbe eti2
    mov col,0
    dec ren
    cmp ren,-1
    jne eti2
}
cout<<"si mino3";
getch();
}


代码到达第一个指令,然后进入无限循环。

最佳答案

您真的是说以下代码行:

for(int i=118;i>0;i++)


这会将i初始化为118,并且每次迭代都加1。它只会越来越大(直到i溢出)。循环是否应该继续的测试是i > 0,该测试将始终为true(直到i溢出)。

您确定自己处于无限循环中吗?也许很多int 21h花费的时间非常非常长。

09-30 20:54