Loops 在x86程序集中打印A到Z和Z到A的程序
我正在编写一个程序,使用循环将a打印到Z,并将Z打印到程序集中的a,但每次打印出“a”后,它都会崩溃Loops 在x86程序集中打印A到Z和Z到A的程序,loops,assembly,x86,masm,irvine32,Loops,Assembly,X86,Masm,Irvine32,我正在编写一个程序,使用循环将a打印到Z,并将Z打印到程序集中的a,但每次打印出“a”后,它都会崩溃 TITLE A to Z ;loop that prints from a to z & z to a INCLUDE Irvine32.inc .code letter BYTE 65, 0 space BYTE ' ', 0 main PROC MOV ECX, 26 myloop: MOV EDX, offset letter CALL writechar
TITLE A to Z
;loop that prints from a to z & z to a
INCLUDE Irvine32.inc
.code
letter BYTE 65, 0
space BYTE ' ', 0
main PROC
MOV ECX, 26
myloop:
MOV EDX, offset letter
CALL writechar
INC letter
MOV EDX, offset space
CALL writechar
LOOP myloop
CALL crlf
MOV ECX, 26
myloop2:
MOV EDX, offset letter
CALL writechar
DEC letter
MOV EDX, offset space
CALL writechar
LOOP myloop2
exit
main ENDP
END main
这个程序使用了Irvine32.inc库中的一些函数,但我确信这与问题无关,所以我暂时忽略它。如果需要,我会提供更多细节
非常感谢
JLL
以下是Irvine32.inc文件:
; Include file for Irvine32.lib (Irvine32.inc)
INCLUDE SmallWin.inc ; MS-Windows prototypes, structures, and constants
.NOLIST
; Last update: 1/27/02
;----------------------------------------
; Procedure Prototypes
;----------------------------------------
ClrScr PROTO ; clear the screen
Crlf PROTO ; output carriage-return / linefeed
Delay PROTO ; delay for n milliseconds
DumpMem PROTO ; display memory dump
DumpRegs PROTO ; display register dump
GetCommandTail PROTO ; get command-line string
GetDateTime PROTO, ; get system date and time
startTime:PTR QWORD
GetMseconds PROTO ; get milliseconds past midnight
Gotoxy PROTO
IsDigit PROTO ; return ZF=1 if AL is a decimal digit
Randomize PROTO ; reseed random number generator
RandomRange PROTO ; generate random integer in specified range
Random32 PROTO ; generate 32-bit random integer
ReadInt PROTO ; read signed integer from console
ReadChar PROTO ; reach single character from console
ReadHex PROTO ; read hexadecimal integer from console
ReadString PROTO ; read string from console
SetTextColor PROTO ; set console text color
WaitMsg PROTO ; display wait message, wait for Enter key
WriteBin PROTO ; write integer to output in binary format
WriteChar PROTO ; write single character to output
WriteDec PROTO ; write unsigned decimal integer to output
WriteHex PROTO ; write hexadecimal integer to output
WriteInt PROTO ; write signed integer to output
WriteString PROTO ; write null-terminated string to output
; Copy a source string to a target string.
Str_copy PROTO,
source:PTR BYTE,
target:PTR BYTE
; Return the length of a null-terminated string..
Str_length PROTO,
pString:PTR BYTE
; Compare string1 to string2. Set the Zero and
; Carry flags in the same way as the CMP instruction.
Str_compare PROTO,
string1:PTR BYTE,
string2:PTR BYTE
; Trim a given trailing character from a string.
; The second argument is the character to trim.
Str_trim PROTO,
pString:PTR BYTE,
char:BYTE
; Convert a null-terminated string to upper case.
Str_ucase PROTO,
pString:PTR BYTE
;-----------------------------------
; Standard 4-bit color definitions
;-----------------------------------
black = 0000b
blue = 0001b
green = 0010b
cyan = 0011b
red = 0100b
magenta = 0101b
brown = 0110b
lightGray = 0111b
gray = 1000b
lightBlue = 1001b
lightGreen = 1010b
lightCyan = 1011b
lightRed = 1100b
lightMagenta = 1101b
yellow = 1110b
white = 1111b
.LIST
我有点恼火——你调用了名为
writechar
和crlf
的函数,然而,基普先生创建了这些函数并调用它们writechar
和crlf
您只需打开Irvine32.asm并查看WriteChar
的源代码,在程序开始时,Irvine先生留下了以下内容供大家查看:
WriteChar PROC
;
; Write a character to the console window
; Recevies: AL = character
; Last update: 10/30/02
; Note: WriteConole will not work unless direction flag is clear.
;------------------------------------------------------
因此,在调用WriteChar
之前,将要打印的字符的ASCII值放入AL
而不是地址
MOV al, letter
CALL WriteChar
INC letter
另外,正如Frank提到的,变量应该位于
.data
或.data?
部分,而不是.code
部分,可能是写入.code
部分。试着把字母
放在数据
段中。你能发布writechar的功能规范吗?我假设Irvine32.inc对它的功能和需要的参数有一些评论。函数名意味着它打印一个字符。但是,您正在传递以NULL结尾的字符串的地址。我想我明白了程序崩溃的原因,但我需要更多地了解writechar应该做什么。难道writechar
不需要AL
中的字符(而不是EDX
中的字符地址)?我发布了Irvine32.INCLUDE文件,希望这会有所帮助。我希望Irvine32.inc文件能提供更多的见解。不幸的是,它没有准确地描述它期望的参数,以及它们期望的位置。也就是说,字符应该在EDX中(DL,真的),还是EDX应该指向内存中的字符?另外,这个练习使用的是什么汇编程序?谢谢。你的回答很准确,我的程序现在运行得很好。祝你过得愉快!:)