1

I am working on a project to organize students mark in 3 exam using assembly language.

I want the emu to CMP the user's string by the ones in the text file, so if ZF set to 1, the emu will print the hole student's information (ID, Full Name, exams marks), that came from the compassion.

Here is the code, I take help from you guys.

ORG 100H 
     MOV DX, OFFSET MSG1
     MOV AH, 9H
     INT 21H
     MOV DX, OFFSET MSG2
     MOV AH, 9H
     INT 21H 
     MOV DX, OFFSET LNBF  ; GET STRING FROM USER
     MOV AH, 0AH
     INT 21H  


     MOV AL, 0            ; OPEN MY FILE
     MOV DX, OFFSET FILE
     MOV AH, 3DH
     INT 21H 

     ;  READ FROM FILE
     MOV BX, AX           ; MOV HANDLER TO BX 
     MOV CX, 1            ; READ CHAR ONE BY ONE
     LEA DX, DATABF        
     INT 21H 
     RET

FILE DB "MY.txt",0
LNBF DB 1EH,? 
MSG1 DB "FIND A STUDENT BY HIS/HER LAST NAME:$"
MSG2 DB 0DH,0AH,0DH,0AH,"ENTER THE STUDENT'S LAST NAME->: $"  
DATABF DW 0FFFH
phuclv
  • 37,963
  • 15
  • 156
  • 475
  • 3
    There is an instruction for that: `REP CMPSB`. Its usage info can be [found here](https://www.felixcloutier.com/x86/cmps:cmpsb:cmpsw:cmpsd:cmpsq) and [here](https://www.felixcloutier.com/x86/rep:repe:repz:repne:repnz). – zx485 Apr 11 '20 at 18:30

1 Answers1

0

Do correct these errors before you continue:

  • LNBF DB 1EH,? does a bad job setting up a buffer to input the student's name! It overwrites MSG1 instead of providing a decent dedicated buffer.
    The correct way is : LNBF DB 30, 0, 30 dup (0)
    For detailed info about the DOS.BufferedInput function 0Ah see How buffered input works

  • Your READ FROM FILE code forgets to specify the required function number 3Fh.
    Use mov ah, 3Fh. Also you should not neglect the possibility that an error is returned via the carry flag!


Below is an example that you can use. It compares the carriage return-terminated name in the inputbuffer with the zero-terminated name in the text file. (The file could of course be using any string terminator that suits you...)

    mov si, offset LNBF + 2   ; -> SI is address of student's name.
More:
    call ReadOneCharFromFile  ; -> AL
    cmp  al, 0
    je   SkipToNextNameInFile
    cmp  al, [si]
    jne  SkipToNextNameInFile
    inc  si
    cmp  byte [si], 13
    jne  More
    call ReadOneCharFromFile  ; -> AL
    cmp  al, 0
    jne  SkipToNextNameInFile
MatchFound:
    ...
SkipToNextNameInFile:
    ...
Sep Roland
  • 33,889
  • 7
  • 43
  • 76