實驗二掌握串操作指令的用法,注意df標識位以及源串、目標串的儲存和改變。
掌握位運算指令的用法,注意目標串的儲存和改變。
實驗要求:
(1)編寫子程式
(2)在主程式中呼叫子程式
(3)實現主程式與子程式的引數傳遞
(4)實現串指令的呼叫。
(5)練習使用位運算
寫乙個過程stata,該過程統計乙個串(串中元素為字長)中有多少正整數,該過程有堆疊三個引數傳遞。
(1)串的位址
(2)串中元素的個數。(傳遞引數的長度為字長)
(3)儲存結果的乙個變數的位址。
;
program
:統計串中正整數的數量
;author:nonoas
;date
:20191210
.386
.model flat
exitprocess proto near32 stdcall, dwexitcode:dword
include io.h ; header file for
input
/output
cr equ 0dh ; carriage return character
lf equ 0ah ;
line feed
.stack 4096
; reserve 4096
-byte stack
.data
; reserve storage for
data
prtinput byte cr,lf,"original string:",
0string word 80 dup (?)
prtresult byte cr,lf,
"the quantity of positive integer is:",0
result word ?
.code ; start of main program code.
strlen proc near32 ;
get the length
ofstring
push ebp
mov ebp,esp
pushf
push ebx
sub eax,eax
mov ebx,[ebp+
8]whilechar:
cmp byte ptr [ebx],
0 je endwhilechar
inc eax
inc ebx
jmp whilechar
endwhilechar:
pop ebx
popf
pop ebp
ret 4
strlen endp
;count the number of
string
stata proc near32
push ebp
mov ebp,esp
pushf
mov ecx,[ebp+
14] ;
length
mov ebx,[ebp+
10] ;addr
mov dx,[ebp+
8] ;count
forfind:
mov al,[ebx]
cmp al,
'0' jb endloop
cmp al,
'9' ja endloop
inc dx
endloop:
inc ebx
loop forfind
popf
pop ebp
ret 10
stata endp
_start:
output prtinput
input
string,80
lea eax,
string
push eax
call strlen ;
get the length
ofstring
mov ecx,eax
push ecx
lea ebx,
string
push ebx
mov dx,
0 push dx
call stata
output prtresult
itoa result,dx
output result
invoke exitprocess,0;
exit
with
return code 0
public _start ; make entry point
public
end;
endof source code
從鍵盤輸入乙個資料,顯示其二進位制表示方式在在螢幕上。(提示用位運算指令完成)
例如:從鍵盤輸入資料為12,它的二進位制為0000 0000 0000 0000 0000 0000 0000 1100,
那麼在螢幕上顯示 00000000000000000000000000001100b
;
program
:輸出乙個十進位制數的二進位制
;author:nonoas
;date
:20191210
.386
.model flat
exitprocess proto near32 stdcall, dwexitcode:dword
include io.h ; header file for
input
/output
cr equ 0dh ; carriage return character
lf equ 0ah ;
line feed
.stack 4096
; reserve 4096
-byte stack
.data
; reserve storage for
data
prtin byte "enter a number:",
0prtresult byte "its binary value is:",cr,lf,
0prtunits byte
" b",0
strnum byte
30 dup(?)
intnum word ?
result word ?
.code ; start of main program code
_start:
output prtin
input strnum,
20 atoi strnum
mov intnum,ax
lea ebx,strnum
mov ecx,
16output prtresult
forout:
mov dx,intnum
rol dx,
1;cycle left
mov intnum,dx
and dx,1;
and the number
itoa result,dx
output result
loop forout
output prtunits
invoke exitprocess,0;
exit
with
return code 0
public _start ; make entry point
public
end;
endof source code
8086彙編 串處理指令
於ibm pc組合語言程式設計 沈美明 溫冬嬋 編著 movs 串傳送 movs dst,src 如 movs es byte ptr di ds si 源串放在資料段中,目的串在附加段中 源串首位址放入si暫存器 目的串首位址放入di暫存器 資料長度放入cx暫存器 建立方向標誌cld,std cm...
8086彙編指令大全 串操作型別
型別 彙編指令格式 功 能運算元說明 時鐘週期數 位元組數串 操 作 類 movsb movsw di si si si 1,di di 1 di si si si 2,di di 2 不重複 18 重複 9 17 rep 不重複 18 重複 9 17 rep 1 1stosb stosw di a...
8086彙編下的ret指令和retf指令
在這裡主要是想做個記錄 當cpu執行指令ret的時候,會進行下面的操作當cpu執行指令retf的時候相當於進行了下面的操作其實就相當於cpu在執行ret指令的時候就是在執行下面的彙編語句 pop ip cpu在執行retf指令的時候其實就是在執行下面的彙編語句 pop ip pop cs 關於下面的...