CS计算机代考程序代写 .code16

.code16
.global start

start:

# Code …

movw $0, %ax
movw $0, %bx
movw $0, %cx
movw $0, %dx
#…
call print_string
call get_symbol
#…
call math
jmp start

get_symbol:
#…
cmp $0x71, %a; #compare input to check if it is a q(0x71) (inifinite loop)
je done
#…
ret

print_newline:
movb $0x0d, %al #store ASCII value for carriage return character
movb $0x0E, %ah #set bios interrupt to print
int $0x10 #print carriage return character

movb $0x0a, %al
movb $0x0E, %ah
int $0x10
ret
print_string:
lodsb
testb %al, %al
jz print_string_done
movb $0x0E, %ah
int $0x10
jmp print_string

print_string_done:
ret

math:
#…
movb $0x2F, %al #ASCII value of divide sign
cmp %al, %dl. #check if operator is an divide sign
je divide
#…
divide:
movw $0, %ax #clar ax
movw %bx, %ax #move bx to ax // ax= bx = 4
idiv %cl # pts %ax/%c; -> %a; and remainder into %ah
movw $0, %bx #clear bx
movb %al, %bl #store quotient in bl
jmp print_ans

print_ans:
movw $ans_msg, %si #load the first msg into %si
call print_string

print_num: #bl has the answer
movb $0x09, %al
cmp %al, %bl #bl>9?
jg print_two_digits #if so, jump out to print he two digit anser, else print single digit

movb %bl, %al
add $0x30, %al
movb $0x0E, %ah
int $0x10
jmp print_num_done

print_two_digits:
mov %bx, %ax
movb $10, %cl
idiv %cl #puts %ax/%cl to %a; and remainder into %ah
#AL has the tenth digit, AH has the ones digit

movb %ah, %dl #store the ones digit in dl for printing

add $0x30, %al #AL Dec to ASCII
movb $0x0E, %ah #set bios interrupt to print
int $0x10 # BIOS interrupt to print tens digit

movb %dl, %al #load dl back to al for printing al = 3
add $0x30, %al #dec to ASCII al = 3 + 30 = 33
int $0x10 # BIOS interrupt to print ones digit, 3 gets printed
jmp print_num_done

done:
jmp done #inifinity loop

print_num_done:
call print_newline #print a new line
ret
# Pre-defined strings
op_one_msg:
.string “Input operand1: ”

op_two_msg:
.string “Input operand2: ”

operator_msg:
.string “Input operator: ”

ans_msg:
.string “The answer is: ”

# Make sure the file is of the correct size
# What does a file of this end with?

.fill 510 -(. -start), 1, 0

.byte 0x55
.byte 0xAA