如何使用Irvine32 for x86从表中写入文本文件?

时间:2018-05-19 03:41:16

标签: assembly masm32 irvine32

我试图获取输出到控制台的名称和等级列表,并将它们写入文本文件lab4.txt。我能够创建该文件,但我不知道我应该把表格放到我的文件代码中以及如何解决这个问题。我对汇编代码相当新,所以我的一些方法可能非常不正统。只是寻找一些如何在我的文本文件上打印的指导。谢谢。如果我的代码出现奇怪而不完全是块,我道歉。我不知道发生了什么。

TITLE  Lab #4 Grade Output Progra                   (main.asm)

INCLUDE Irvine32.inc
.data
myMessage1 BYTE "Please enter the students name: ",0dh,0ah,0
myMessage2 BYTE "Please enter ",0
myMessage3 BYTE "'s grade: ",0
InputBufferName BYTE 20 Dup(?)
InputBufferGrade BYTE 20 Dup(?)
NumInTable BYTE 00h
printCounter BYTE 00h
FieldSizeName EQU 26
FieldSizeGrade EQU 3
GradeTable BYTE 20 DUP(FieldSizeGrade DUP(?))
NameTable BYTE 20 DUP(FieldSizeName DUP(" "))
color DW  7, 0

stringLength = 1000
filename BYTE "lab4.txt",0, 0Dh, 0Ah
fileHandle DWORD ?
buffer BYTE stringLength DUP(?)
bytesWritten DWORD ?



.code
main PROC



S1:
    call Clrscr

mov  edx,OFFSET myMessage1
call WriteString                  ; Asks for name

mov edx, OFFSET InputBufferName 
mov ecx, 26      
call ReadString                  ; input name into input buffer


cmp eax, 0
JE E1                            ;checking to see if there is an input and if not jumping to exit


mov esi, OFFSET InputBufferName
mov edi, OFFSET NameTable
mov eax, FieldSizeName
mul NumInTable
add edi,eax
mov ecx, FieldSizeName
rep movsb                        ;moves name into nametable

call Clrscr

A1:
    mov edx, OFFSET myMessage2
    call WriteString
L1: 


lea edx, InputBufferName
call WriteString                 ;prints name in request statement for grade

mov edx, OFFSET myMessage3
call WriteString

mov edx, OFFSET InputBufferGrade 
mov ecx, 2      
call ReadString                  ; Reads grade


cmp InputBufferGrade, "A"
JE R1
cmp InputBufferGrade, "B"
JE R1
cmp InputBufferGrade, "C"
JE R1
cmp InputBufferGrade, "D"
JE R1
cmp InputBufferGrade, "F"
JE R1
cmp InputBufferGrade, "a"
JE R1
cmp InputBufferGrade, "b"
JE R1
cmp InputBufferGrade, "c"
JE R1
cmp InputBufferGrade, "d"
JE R1
cmp InputBufferGrade, "f"
JE R1
JMP A1

R1:

mov esi, OFFSET InputBufferGrade
mov edi, OFFSET GradeTable
mov eax, FieldSizeGrade
mul NumInTable
add edi,eax
mov ecx, FieldSizeGrade
rep movsb


inc NumInTable
cmp NumInTable, 20
JL S1


call Clrscr

P1:

mov ax, 7
call SetTextColor

mov dl, 5
mov dh, 3                            ;setting place for name
add dh, printCounter
call Gotoxy



mov edi, OFFSET NameTable
mov eax, FieldSizeName
mul printCounter
add edi,eax  
lea edx, nameTable[eax]
call WriteString

mov dl, 32
mov dh, 3                             ;setting place for letter grade
add dh, printCounter
call Gotoxy

mov ax, color
call SetTextColor                     ;setting color 



mov edi, OFFSET GradeTable
mov eax, FieldSizeGrade
mul printCounter
add edi,eax
mov ebx,eax
cmp gradeTable[ebx], "A"
JE C6
cmp gradeTable[ebx], "B"
JE C6
cmp gradeTable[ebx], "C"
JE C6
cmp gradeTable[ebx], "a"
JE C6
cmp gradeTable[ebx], "b"
JE C6
cmp gradeTable[ebx], "c"
JE C6
mov ax, 7
cmp gradeTable[ebx], "D"
JNE C4
mov ax, 14
call SetTextColor
JMP C6

C4:

cmp gradeTable[ebx], "d"
JNE C5
mov ax, 14
call SetTextColor
JMP C6

C5:

mov ax, 12
call SetTextColor

C6:
mov eax, ebx
lea edx, gradeTable[eax]
call WriteString

inc printCounter
cmp printCounter, 20
JL P1


call crlf

mov eax, 7                           ;resetting color
call SetTextColor



INVOKE CreateFile,
OFFSET filename, GENERIC_WRITE, DO_NOT_SHARE, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0
mov fileHandle, eax

INVOKE WriteFile,
    fileHandle, OFFSET buffer, stringLength,
    ADDR bytesWritten, 0
INVOKE CloseHandle, fileHandle

call waitMsg



JMP S1                               ;jumping to beginning




E1:
exit
main ENDP

END main

0 个答案:

没有答案