CATEGORII DOCUMENTE |
Bulgara | Ceha slovaca | Croata | Engleza | Estona | Finlandeza | Franceza |
Germana | Italiana | Letona | Lituaniana | Maghiara | Olandeza | Poloneza |
Sarba | Slovena | Spaniola | Suedeza | Turca | Ucraineana |
DOCUMENTE SIMILARE |
|
Latvijas Universitate
Fizikas un matematikas fakultate
Datorzinatņu nodaļa
Datoru arhitektūra:
teorija,
kontroldarbi,
praktiskais darbs
Parveidoana decimala sepadmitnieku sistēma
Piepildīt rindu ar tukumiem
Risinajums
xyzt
Skaitlis n baitos papildkoda
n |
mazakais skaitlis |
lielakais skaitlis |
-128 (80h) |
127 (7Fh) |
|
-32768 (8000h) |
32767 (7FFFh) |
|
-2147483648 (80000000h) |
2147483647 (7FFFFFFFh) |
2. Lai papildkoda attēlotu -1234, vajadzīgi vismaz 2 baiti.
3. 1234 n baitos papildkoda
n |
skaitļa attēlojums |
nav iespējams |
|
04D2h |
|
000004D2h |
Risinajums
xyzt
IP=EyzF=E23Fh EA=2zytF=2324Fh=CS*16+IP (izpildadrese)
CS=(EA-IP)/16
2324F - E23F
CS=1501h
Risinajums
xyzt a=2*(x+y+z+t+3)=26 b=2*(z+t)+5=19 =masa c=5*a=130 =masb d=a+1=27=001Bh =masc CX=0 DI=6-d*2=-48 AX=-13+4*masb+(d-4)*masa+masa-1B00h=-5949 |
Risinajums
;xyzt ifL1: cmp AX,-1 ;noverte q jge thenL1 ;q>=z-t jmp elseL1 ;q<z-t thenL1: mov BX,1 ;x imul BX ;x*q sub AX,2 ;x*q-y jmp fiL1 elseL1: mov BX,1 imul BX ;izples q pa DX:AX mov BX,4 ;z+1 idiv BX ;q dala ar z+1 mov AX,DX ;parvieto atlikumu uz AX add AX,4 ;(q mod (z+1))+t fiL1:
Risinajums
;xyzt ifL1: cmp AX,1 ;noverte q jge thenL1 ;q>=1 jmp elseL1 ;q<1 thenL1: mov CX,AX ;uzstada cikla skaititaju mov BX,0 ;inicie starprezultatu repeatL2: mov AX,6 ;t+2 imul CX ;(t+2)*i sub AX,5 ;(t+2)*i-(z+2) imul CX ;((t+2)*i-(z+2))*i sub AX,4 ;((t+2)*i-(z+2))*i-(y+2) imul CX ;(((t+2)*i-(z+2))*i-(y+2))*i add AX,1 ;(((t+2)*i-(z+2))*i-(y+2))*i+x add BX,AX ;pieskaita summas locekli starprezultatam untilL2: loop repeatL2 ;atkarto nakosajiem summas locekliem mov AX,BX ;izdod rezultatu jmp fiL1 elseL1: mov AX,0 ;izdod rezultatu fiL1: |
Procedūra NexCom parveido doto vektoru c, kas sastav no n elementiem, no kuriem katrs ir vai nu 0, vai 1, par citu vektoru, kur satur to pau skaitu nuļļu un vieninieku, taču cita secība. Ja sakotnējam vektoram c[1:n] pirmajas r komponentēs ir vieninieki, bet parējas - nulles, tad atkartoti izsaucot procedūru NexCom var iegūt visas vektora c substitūcijas. Substitūciju meklēanas process beidzas, līdzko tiek iegūts vektors c, kam pirmajas n-r komponentēs ir nulles un parējas - vieninieki. aja gadījuma atgrieanas no procedūras notiek caur iezīmi complete. Ja dotais vektors c ir nulles vektors, tad atgrieanas no procedūras notiek caur iezīmi null.
procedure NexCom(n,complete,null)dataresult:(c);
value n; integer n; array c; label complete,null;
begin
integer p,m,k;
for k:=1 step 1 until n do
if c[k]=1 then go to aa;
go to null;
aa: p:=0;
for m:=k+1 step 1 until n do
if c[m]=1 then p:=p+1 else go to bb;
bb: if p+k=n then go to complete;
c[k+p+1]=1;
for m:=k+p step -1 until k do c[m]:=0;
for m:=1 step 1 until p do c[m]:=1
end NexCom;
Piezīme. Lai realizētu kontroli par atgrieanos no procedūras NexCom (iezīmes complete un null), ta parveidota par funkciju, kuras iespējamas vērtības ir 1 (atbilst iezīmei complete), -1 (atbilst iezīmei null) un 0 (parējos gadījumos).
program DAPD;
const max=8;
complete= ;
null=- ;
type vector=array[ ..max]of byte;
var cString: string[max];
cLength: integer;
c: vector;
status: integer;
i: integer;
function NexCom(c: vector; n: integer): integer; external;
begin
writeln('Datoru arhitektura: praktiskais darbs');
writeln('Gatis MEDNIS, LU FMF 3DZ3, 12.12.1999.');
writeln;
writeln('Programma 'NexCom' izdruka visas iespejamas substitucijas binaram n-elementu ');
writeln('vektoram c, kas uzdots forma (1,,1,0,,0). Pedeja substitucija ir forma');
writeln( );
writeln;
writeln;
write('Ievadiet vektoru c (piemeram, 1100)! ');
read(cString);
writeln;
cLength:= ;
while (cString[cLength]= )or(cString[cLength]= ) do
begin
c[cLength]:=ord(cString[cLength])-ord( );
write(c[cLength]);
cLength:=cLength+
end;
cLength:=cLength- ;
writeln;
status:=NexCom(c,cLength);
while status= do
begin
for i:= to cLength do
write(c[i]);
writeln
status:=NexCom(c,cLength)
end;
writeln;
case status of
complete: writeln('Atrasta pedeja substitucija, programmas beigas.');
null: writeln('c ir nulles vektors, programmas beigas')
end
end
Cseg segment para public 'CODE'
assume CS:Cseg
public NexCom
NexCom proc near
;----konstantes----- ----- ----------------
RetSave equ 2 ;tuva procedura, atgriesanas adrese IP
RegSave equ 14 ;steka saglaba 7 registrus
n equ word ptr [BP+RegSave+RetSave]
;2. parametrs - masiva c elementu skaits
cAddr equ word ptr [BP+RegSave+RetSave+2]
;1. parametrs - masiva c nobide
c equ [BX] ;masiva c nobide
OK equ 0 ;izpildes statusa vertiba
complete equ 1 ;izpildes statusa vertiba
null equ -1 ;izpildes statusa vertiba
;----mainigie----- ----- --------- ----- ----
status equ AX ;funkcijas izpildes statuss
p equ DX
m equ DI
k equ SI
;----vides saglabasana----- ----- ---------
push BX
push CX
push DX
push SI
push DI
push BP
pushf
mov BP,SP
;----sakuma uzstadijumi----- ----- --------
mov BX,cAddr ;BX ieliek masiva c nobidi
dec BX ;1. masiva c elementam bus nobide +1
mov CL,0 ;CL=0
mov CH,1 ;CH=1
;----aprekinu dala----- ----- -------------
mov k,1 ;for k:=1
forL1:
cmp k,n ;until n
jg exitL1
doL1:
ifL2:
cmp c[k],CH ;if c[k]=1
thenL2:
je aa ;then go to aa
fiL2:
nextL1:
inc k ;step 1
jmp forL1
exitL1:
mov status,null ;go to null
jmp returnL8
aa:
mov p,0 ;p:=0
mov m,k ;
add m,1 ;;for m:=k+1
forL3:
cmp m,n ;until n
jg exitL3
doL3:
ifL4:
cmp c[m],CH ;if c[m]=1
jne elseL4
thenL4:
add p,1 ;then p:=p+1
jmp fiL4
elseL4:
jmp bb ;else go to bb
fiL4:
nextL3:
inc m ;step 1
jmp forL3
exitL3:
bb:
mov DI,p ;
add DI,k ;
ifL5:
cmp DI,n ;if p+k=n
jne fiL5
thenL5:
mov status,complete ;then go to complete
jmp returnL8
fiL5:
add DI,1 ;
mov c[DI],CH ;c[k+p+1]:=1
sub DI,1 ;;for m:=k+p
forL6:
cmp m,k ;until k
jl exitL6
doL6:
mov c[m],CL ;c[m]:=0
nextL6:
dec m ;step -1
jmp forL6
exitL6:
mov m,1 ;for m:=1
forL7:
cmp m,p ;until p
jg exitL7
doL7:
mov c[m],CH ;c[m]:=1
nextL7:
inc m ;step 1
jmp forL7
exitL7:
mov status,OK
;----vides atjaunosana----- ----- ---------
returnL8:
popf
pop BP
pop DI
pop SI
pop DX
pop CX
pop BX
ret 4 ;iznem no steka 2 parametrus
NexCom endp
Cseg ends
end
Politica de confidentialitate | Termeni si conditii de utilizare |
Vizualizari: 2127
Importanta:
Termeni si conditii de utilizare | Contact
© SCRIGROUP 2024 . All rights reserved