[英]How do I print the contents of a register in x86 assembly to the console? I'm running Linux
[英]How do I actually print the numbers I'm storing in the variables X and Y? Assembly x86
我需要讀取和打印存儲在兩個變量中的數字(我正在做一個菜單程序)但是當我打印它們時它會打印 ASCII 表中的小寫字母(比如 a、b、c 而不是 2、3、4) . 我知道我應該減去 48 並乘以,但我沒有找到關於如何在我的程序中實現該轉換的好解決方案。 我正在使用裝配 x86,TASM。
這是讀取輸入的代碼:
標語:
mov dx, offset prompt1
mov ah, 9
int 21h
input_x:
mov bx, offset x ; point BX to the start of the array x
mov cx, 10 ; set the counter to the number of elements in the array x
input_loop1:
mov ah, 01h ; function to read a single character
int 21h ; call DOS function
mov [bx], al ; store the character in the current array element
inc bx ; move to the next array element
loop input_loop1 ; repeat until counter reaches 0
jmp input_y
input_y:
mov dx, offset prompt2
mov ah, 9
int 21h
mov bx, offset y ; point BX to the start of the array y
mov cx, 10 ; set the counter to the number of elements in the array y
input_loop2:
mov ah, 01h ; function to read a single character
int 21h ; call DOS function
mov [bx], al ; store the character in the current array element
inc bx ; move to the next array element
loop input_loop2 ; repeat until counter reaches 0
jmp bucla
我認為問題來自我的打印代碼:
了解:
mov dx, offset prompt3
mov ah, 9
int 21h
print_x:
mov bx, offset x ; point BX to the start of the array x
mov cx, 10 ; set the counter to the number of elements in the array x
print_loop1:
mov dl, [bx] ; move the value of the current array element to DL
add dl, 48 ; convert the number to its ASCII equivalent
mov ah, 02h ; function to print a single character
int 21h ; call DOS function
inc bx ; move to the next array element
loop print_loop1 ; repeat until counter reaches 0
jmp print_y
print_y:
mov dx, offset prompt4
mov ah, 9
int 21h
mov bx, offset y ; point BX to the start of the array y
mov cx, 10 ; set the counter to the number of elements in the array y
print_loop2:
mov dl, [bx] ; move the value of the current array element to DL
add dl, 48 ; convert the number to its ASCII equivalent
mov ah, 02h ; function to print a single character
int 21h ; call DOS function
inc bx ; move to the next array element
loop print_loop2 ; repeat until counter reaches 0
jmp bucla ; return to main loop
如何實際打印存儲在變量 X 和 Y 中的數字?
您已將數字的 ASCII 表示形式存儲在 X 和 Y 變量中。 因此打印數字不需要任何轉換。 只需從afisare代碼中刪除行add dl, 48
。
但是,如果您確實想將輸入的數字從文本轉換為 integer,請閱讀使用 DOS 輸入多基多位帶符號數字中的內容。
要顯示此類整數,請閱讀Displaying numbers with DOS 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.