我遇到了一個問題,在程序集8086中只有一行顯示4個不同的字符串。輸出應該是「你是」,「名字」,「中間名」和「姓氏」。它與前兩項工作正常,但最後兩個重疊與第一個,意思是,「你」最終被重寫「中間名」,並進一步被「姓氏」重寫。如果在最後兩行之前使用下一行,它會打印出正常,但我想在一行中顯示所有4個字符串,而不是以3行顯示。我試圖搜索網絡,但大多數答案僅限於顯示2個字符串。爲什麼多個字符串在彙編中的輸出中重疊/覆蓋?
;=====output======
mov ah, 09
mov dx, offset crlf ;next line
int 21h
mov ah, 09
mov dx, offset msg4 ;displays "You are"
int 21h
mov ah, 09
mov dx, offset string1 + 2 ;displays inputted "first name"
int 21h
mov ah, 09
mov dx, offset string3 + 2 ; this should appear next to string1,
int 21h not rewrite msg4...
mov ah, 09
mov dx, offset string2 + 2 ; this should appear next to string3, not
int 21h rewrite msg4 and string3
這就是輸出端像:
Enter 1st name: Helena
Enter last name: Ramos
Enter middle name: Ang
Ramosre Helena ;"Ang" rewrites "You are", and then
"Ramos" rewrites it again
; This is what I want to see:
; You are Helena Ang Ramos
我非常組裝一個新手,我的教授是不完全的最有幫助的老師,因爲我們不」沒有任何書籍,課堂講義只定義說明,而實驗練習幾乎是複製粘貼他編寫的代碼,所以我的大多數同學都是在實際編程中自學。這只是作業的一小部分,實際的作業要求我們顯示中間名,而不是中間名,但我甚至無法正確顯示所有4個字符串!在這一點上,我有一種感覺,如何將字符串推入堆棧有一個問題,但是我有限的知識阻止了我找出原因。如果你有興趣
全碼:
org 100h
.model small
.stack 200
.data
msg1 db "Enter 1st name: $"
string1 db 50,?,50 dup ('$')
msg2 db 0ah, 0dh, "Enter last name: $"
string2 db 50,?,50 dup ('$')
msg3 db 0ah, 0dh, "Enter middle name: $"
string3 db 50,?,50 dup ('$')
msg4 db 0ah, 0dh, "You are $"
crlf db 0ah, 0dh, '$'
.code
mov ax, @data
mov ds, ax
mov ah, 09
mov dx, offset msg1
int 21h
mov ah, 0ah
mov dx, offset string1 ;input first name
int 21h
mov ah, 09
mov dx, offset msg2
int 21h
mov ah, 0ah
mov dx, offset string2 ;input last name
int 21h
mov ah, 09
mov dx, offset msg3
int 21h
mov ah, 0ah
mov dx, offset string3 ;input middle name
int 21h
;=====output======
mov ah, 09
mov dx, offset crlf ;next line
int 21h
mov ah, 09
mov dx, offset msg4 ;displays "You are"
int 21h
mov ah, 09
mov dx, offset string1 + 2 ;displays inputted "first name"
int 21h
mov ah, 09
mov dx, offset string3 + 2 ; this should appear next to string1,
int 21h not rewrite msg4...
mov ah, 09
mov dx, offset string2 + 2 ; this should appear next to string3, not
int 21h rewrite msg4 and string3
我使用8086,所以movzx不起作用。我試過'mov bl,[dx-1]',但是它會導致一個錯誤,說'(63)十六進制可能沒有零前綴;或沒有'h'後綴;或錯誤的尋址;或undefined var:[dx-01h]'我嘗試過使用'sub [dx],01'或'dec [dx]'來解決它,但它會導致相同的錯誤。間接尋址不接受dx,所以我嘗試用bx替換它,並且沒有錯誤,但仍然覆蓋。我被dx卡住了。 – AnAn
@安娜哦,真正的模式的喜悅,我完全忘了那些。我將在幾分鐘內(在得到一些彙編器來驗證代碼之後)用有效的實模式尋址和8086指令編輯答案。順便說一句'sub [dx],1'會從內存中減去1,而不是'dx'。括號'[]'的意思是「使用內部括號中的值作爲內存中的地址以在那裏操作數值」。 – Ped7g
@AnAn在答案的最後......基本上是新的答案......但是你需要更加努力地嘗試自己,我並不是指隨機猜測並嘗試從其他地方複製代碼副本。這可能適用於高級語言,但在彙編中,您必須完全理解您寫的內容,在合理的時間內「猜出」正確的代碼幾乎是零。因此,根據您當前的問題(「堆棧」提及,顛倒LF + CR,無法使用錯誤的[[dx]'尋址修復我的原始代碼,無法使用調試器),您需要閱讀某本書/教程,花幾周時間它,並試驗代碼。 – Ped7g