我写了一个汇总代码来总结五个数字。然后将最终值存储在存储器中。
dtseg segment
data dw 27345,28521,29533,30105,32375
sum dw ?
MSG1 DB "The sum is : $"
dtseg ends
;---------------------
cdseg segment
main proc far
assume cs:cdseg,ds:dtseg,ss:stseg
mov ax,dtseg
mov ds,ax
clc ; clear the carry
mov si,offset data ; first location of data
mov cx,04 ; setting the counter
mov ax,0 ; clear ax
mov bx,ax ; clear bx
back:add ax,[si] ; the first round: 0+27345
adc bx,0 ; if there is a carry, add that to bx
inc si ; two inc because traversing words
inc si
dec cx ; count down
jnz back ; do that for other numbers
mov sum,ax ; the final value
mov sum+2,bx ; the carries are stored in bx
lea dx,MSG1 ; trying to display the result
mov ah,09h
int 21h
mov ah, 4cH ; return to DOS
int 21h
main endp
cdseg ends
end main
我按照此topic进行了示例,但它在emu8086中不起作用
答案 0 :(得分:3)
This example向您展示如何将DIV
中的WORD值转换为字符串并输出。您想要将DWORD值转换为字符串。在您的情况下,您可以使用DX
在寄存器DX:AX中划分DWORD的优势。在示例xor dx, dx
中设置为0,因此第一个想法是删除行DX
。但是你第一次需要DIV
,那么你必须清除它,因为它保留了dtseg segment
data dw 27345,28521,29533,30105,32375 ; Sum: 147879
sum dw ?, ? ; two WORD = one DWORD
MSG1 DB "The sum is : $"
DECIMAL db "0000000000$" ; space for the result
dtseg ends
;---------------------
cdseg segment
main proc far
assume cs:cdseg,ds:dtseg,ss:stseg
mov ax,dtseg
mov ds,ax
clc ; clear the carry
mov si,offset data ; first location of data
mov cx,5 ; setting the counter
mov ax,0 ; clear ax
mov bx,ax ; clear bx
back:add ax,[si] ; the first round: 0+27345
adc bx,0 ; if there is a carry, add that to bx
inc si ; two inc because traversing words
inc si
dec cx ; count down
jnz back ; do that for other numbers
mov sum,ax ; the final value
mov sum+2,bx ; the carries are stored in bx
call mem_to_dec
lea dx,MSG1 ; trying to display the result
mov ah,09h
int 21h
lea dx,DECIMAL ; trying to display the result
mov ah,09h
int 21h
mov ah, 4cH ; return to DOS
int 21h
main endp
mem_to_dec proc
mov ax, [sum]
mov dx, [sum+2]
mov bx, 10 ; divisor
xor cx, cx ; CX=0 (number of digits)
@First_Loop:
div bx ; DX:AX / BX = AX remainder: DX
push dx ; LIFO
inc cx ; increment number of digits
xor dx, dx ; Clear DX for the next DIV
test ax, ax ; AX = 0?
jnz @First_Loop ; no: once more
mov di, OFFSET DECIMAL ; target string DECIMAL
@Second_Loop:
pop ax ; get back pushed digit
or ax, 00110000b ; to ASCII
mov byte ptr [di], al ; save AL
inc di ; DI points to next character in string DECIMAL
loop @Second_Loop ; until there are no digits left
mov byte ptr [di], '$' ; End-of-string delimiter for INT 21 / FN 09h
ret
mem_to_dec endp
cdseg ends
end main
之后的余数。诀窍是在div之前执行之后的清除。因此它将首次使用,并在每次重复时清除。
DIV
如果结果不适合AX
注册,library(igraph)
g <- ba.game(10) # sample graph
V(g)$label <- LETTERS[1:10] # set vertex labels to A-J
E(g)$foo <- sample(1:5, 10, T) # set custom edge label...
names(edge_attr(g))[which(names(edge_attr(g)) == "foo")] <- "weight" # ... and rename it to weight
write_graph(g, tf <- tempfile(fileext = ".graphml"), "graphml") # export graph
system(paste('"C:\\Program Files (x86)\\Gephi-0.8.2\\bin\\gephi.exe"', tf), wait = FALSE) # adjust path here
会出现问题。然后你得到一个溢出错误。