这是王爽的汇编书上的
- Assembly code
assume cs:codesgdata segment db '1975','1976','1977','1978','1979','1980','1981','1982','1983' db '1984','1985','1986','1987','1988','1989','1990','1991','1992' db '1993','1994','1995' ;这是年份 dd 16,22,382,1356,2390,8000,16000,24486,50065,97479,140417,197514 dd 345980,590827,803530,1183000,1843000,2759000,3753000,4649000,5937000 ;这是收入 dw 3,7,9,13,28,38,130,220,476,778,1001,1442,2248,2793,4037,5635,8226 dw 11542,14430,15257,17800 ;这是人数data endstable segment db 21 dup('year summ ne ?? ')table endscodesg segment start: mov ax,data mov ds,ax mov ax,table mov es,ax mov bx,0 mov bp,0 mov si,0 mov di,0 mov cx,21 s: mov al,[bx+si] mov es:[bp],al mov al,[bx+si+1] mov es:[bp+1],al mov al,[bx+si+2] mov es:[bp+2],al mov al,[bx+si+3] mov es:[bp+3],al ;以上移入年份 add si,54h ;进入总收入 mov dx,[bx+si] mov es:[bp+5],dx mov dx,[bx+si+2] mov es:[bp+7],dx add bx,4 mov si,0 add bp,10h loop s mov bp,0 mov bx,0 mov si,0 mov cx,21 s2: mov ax,[bx+0a8h] ;放入人数 mov es:[bp+0ah],ax add bx,2 add bp,10h loop s2 add si,54h mov bp,0 mov cx,21 s3: mov ax,[bx+si] mov dx,[bx+si+2] mov si,0a8h div [bx+si] ;除以人数 mov [bp+0dh],ax mov si,0 add bx,4 loop s3 mov ax,4c00h int 21h codesg endsend start
D:\RadASM\Masm32\Bin\ML.EXE /c /coff /Cp /nologo /I"D:\RadASM\Masm32\Include" "F:\masm5\proj\8.asm"
Assembling: F:\masm5\proj\8.asm
F:\masm5\proj\8.asm(71) : error A2023: instruction operand must have size
F:\masm5\proj\8.asm(21) : error A2004: symbol type conflict
F:\masm5\proj\8.asm(23) : error A2004: symbol type conflict
F:\masm5\proj\8.asm(84) : warning A4023: with /coff switch, leading underscore required for start address : start
构建时发生错误.
总共编译时间 78 毫秒
------解决方案--------------------------------------------------------
代码没错误,我用EMU8086编译成功,运行也正确。
------解决方案--------------------------------------------------------
你这个是 dos16 类的程序,就不要用 Masm32 来进行编译链接了。找个 Masm6 的更合适。
这些错误信息里,就第一个是确实存在问题的,div [bx+si] 无法确实你将这单元是 byte 还是 word ;所以应该加上 byte ptr 或 word ptr 这样的修饰。
------解决方案--------------------------------------------------------
看错误提示:
71行的问题是不能直接div [内存],应该拿寄存器中转一下。
21行,23行错误相同
开头改为assume cs:codesg,ds:data,es:table即可