Программа 8086 для чтения DOB пользователя и определения возраста - PullRequest
0 голосов
/ 30 октября 2019

Это мой код файла 8086 .COM:

org 100h                       ;tells the assembler that the code that follows should be placed at offset 1000H
.MODEL SMALL                ;Determies the size of code and data pointers
.STACK 100h                 ;Tells the size of the stack
.DATA                       ;Separates variable declaration  
  ;Messages to be displayed
  Message1 DB   "Enter your Full name: $"      
  Message2 DB   "Enter your date of birth : $" 
  Messagee3 DB  "Enter the current date : $"     
.CODE

Main PROC                       ;Beginning of the Main Procedure
    mov ax, @data
    mov ds, ax 
    mov ah, 9h
    mov dx, OFFSET Message1
    int 21h
    mov ah, 0ah
    int 21h
    mov bl, al
    mov ah, 2
    mov dl, 0dh            
    int 21h            
    mov dl, 0ah
    int 21h 
    mov ah, 9h
    mov dx, OFFSET Message2
    int 21h
    mov ah, 0ah
    int 21h
    mov bl, al
    mov ah, 2
    mov dl, 0dh            
    int 21h            
    mov dl, 0ah        
    int 21h   
    mov dl, bl
    mov ah, 0ah
    mov ah, 4ch                ;the program to exit immediately
    int 21h                    ;The standard way to call the interrupt handler 0x21         
Main ENDP                      ;denotes the end of the procedure

END Main                       ;denotes the end of the program, Main.

ret                            ;transfers control to the return address located on the stack.

1 Ответ

0 голосов
/ 30 октября 2019

Вы, кажется, используете функцию DOS AH = 0Ah для получения ввода с клавиатуры, но сначала вам нужно зарезервировать переменную памяти, в которой будут храниться данные. Его адрес должен быть установлен в DS: DX , см. http://www.ctyme.com/intr/rb-2563.htm

Имейте в виду, что число, полученное с клавиатуры, является десятичной цифрой (строкой), которую необходимо преобразовать в двоичный код перед тем, какможно сделать некоторую арифметику с ними. И результат вычитания (ваш возраст в двоичном коде) вы должны преобразовать в строку цифр, прежде чем они смогут отображаться в консоли.

Разделите вашу домашнюю работу на серию макросов инструкций вызова: начните с CALLИнициализация и CALL Завершение , написать код этих процедур, а затем продолжать добавлять дополнительные процедуры: WritePrompt, ReadInput, DecimalToBinary, BinaryToDecimal.

Вы можете посмотреть в макробиблиотеки dosapi и cpuext16 , если вам нужно вдохновение. Вот как будет выглядеть код в EuroAssembler:

Peace16 PROGRAM FORMAT=COM
             INCLUDE dosapi.htm, cpuext16.htm
    Main::   PROC
              StdOutput ="Enter your Full name: "
              StdInput FullName
              StdOutput ="Enter the year of your birth: "
              StdInput  BirthYear
              StdOutput ="Enter this year: "
              StdInput ThisYear
              LodD BirthYear  ; Convert the string of digits to binary number in AX.
              MOV BX,AX       ; Temporary save the converted birth year.
              LodD ThisYear   ; Convert the string of digits to binary number in AX.
              SUB AX,BX       ; Compute the difference.
              StoD Age        ; Convert binary number in AX to string of digits in Age.
              StdOutput ="Hi ",FullName,=" you are now ",Age,=" years old."
              TerminateProgram
    FullName  DB 32*BYTE
    BirthYear DB 6*BYTE
    ThisYear  DB 6*BYTE
    Age       DB 4*BYTE
             ENDP
            ENDPROGRAM

Кстати, попросите вашего учителя перейти с 16-битного кода DOS на 32-битный, это проще, полезнее и вам не придется беспокоиться об эмуляторах. Ваша программа в 32-битной версии Windows будет выглядеть здесь:

Peace32 PROGRAM FORMAT=PE,ENTRY=Main::
         INCLUDE winapi.htm, cpuext32.htm
Main::    PROC
           StdOutput ="Enter your Full name: "
           StdInput FullName
           StdOutput ="Enter the year of your birth: "
           StdInput BirthYear
           StdOutput ="Enter this year: "
           StdInput ThisYear
           LodD BirthYear  ; Convert the string of digits to binary number in EAX.
           MOV EBX,EAX      ; Temporary save the converted birth year.
           LodD ThisYear   ; Convert the string of digits to binary number in EAX.
           SUB EAX,EBX     ; Compute the difference.
           StoD Age        ; Convert binary number in EAX to string of digits in Age.
           StdOutput ="Hi ",FullName,=" you are now ",Age,=" years old."
           TerminateProgram
          ENDP
FullName  DB 32*BYTE
BirthYear DB 6*BYTE
ThisYear  DB 6*BYTE
Age       DB 4*BYTE
        ENDPROGRAM
...