21,459
社区成员
发帖
与我相关
我的任务
分享
enqueue macro
.if count < lengthof queue
inc count
mov eax, number
mov [edi], eax
mov eax, edi
sub eax, offset queue
add eax, 4
cdq
mov ecx, sizeof queue
idiv ecx
mov edi, offset queue
add edi, edx
.else
INVOKE printf, ADDR errfmt, ADDR errmsg2
.endif
endm
69: enqueue
0003106C 83 3D C3 30 03 00 03 cmp dword ptr [count (0330C3h)],3
00031073 7D 2A jge @C0002+60h (03109Fh)
70: .elseif command=="d"
00031075 FF 05 C3 30 03 00 inc dword ptr [count (0330C3h)]
0003107B A1 BF 30 03 00 mov eax,dword ptr [number (0330BFh)]
00031080 89 07 mov dword ptr [edi],eax
00031082 8B C7 mov eax,edi
00031084 2D AF 30 03 00 sub eax,offset queue (0330AFh)
00031089 83 C0 04 add eax,4
0003108C 99 cdq
0003108D B9 0C 00 00 00 mov ecx,0Ch
00031092 F7 F9 idiv eax,ecx
00031094 BF AF 30 03 00 mov edi,offset queue (0330AFh)
00031099 03 FA add edi,edx
69: enqueue
0003109B E9 9F 00 00 68 jmp 6803113F
71: dequeue
000310BF 83 3D C3 30 03 00 00 cmp dword ptr [count (0330C3h)],0
000310C6 7E 27 jle @C0002+0B0h (0310EFh)
72: .if number > 0
000310C8 FF 0D C3 30 03 00 dec dword ptr [count (0330C3h)]
000310CE 8B 06 mov eax,dword ptr [esi]
000310D0 A3 BF 30 03 00 mov dword ptr [number (0330BFh)],eax
000310D5 8B C6 mov eax,esi
000310D7 2D AF 30 03 00 sub eax,offset queue (0330AFh)
000310DC 83 C0 04 add eax,4
000310DF 99 cdq
000310E0 B9 0C 00 00 00 mov ecx,0Ch
000310E5 F7 F9 idiv eax,ecx
000310E7 BE AF 30 03 00 mov esi,offset queue (0330AFh)
000310EC 03 F2 add esi,edx
71: dequeue
000310EE EB 68 jmp @C0002+119h (031158h)
.listall
.386
.model flat, c
.stack 100h
scanf PROTO arg2: Ptr Byte, inputlist: VARARG
printf PROTO arg1: Ptr Byte, printflist: VARARG
.data
in1fmt byte "%s", 0
in2fmt byte "%d", 0
msg1fmt byte 0Ah, "%s", 0
msg3fmt byte 0Ah, "%s%d", 0Ah, 0
msg4fmt byte 0Ah, 0
errfmt byte 0Ah, "%s", 0Ah, 0
msg1 byte "Enter a command, e, d, or s: ", 0
msg2 byte "Enter a positive integer: ", 0
msg3 byte "Te integerr is : ", 0
errmsg1 byte "Error: Invalid entry, try again", 0
errmsg2 byte "Error: Queue is full", 0
errmsg3 byte "Error: Queue is empty", 0
queue sdword 3 dup(7)
command sdword ?
number sdword ?
count sdword 0
.code
enqueue macro
.if count < lengthof queue
inc count
mov eax, number
mov [edi], eax
mov eax, edi
sub eax, offset queue
add eax, 4
cdq
mov ecx, sizeof queue
idiv ecx
mov edi, offset queue
add edi, edx
.else
INVOKE printf, ADDR errfmt, ADDR errmsg2
.endif
endm
dequeue macro
.if count > 0
dec count
mov eax, [esi]
mov number, eax
mov eax, esi
sub eax, offset queue
add eax, 4
cdq
mov ecx, sizeof queue
idiv ecx
mov esi, offset queue
add esi, edx
.else
INVOKE printf, ADDR errfmt, ADDR errmsg3
mov number, -1
.endif
endm
main proc
mov edi, offset queue + 0
mov esi, offset queue + 0
INVOKE printf, ADDR msg1fmt, ADDR msg1
INVOKE scanf, ADDR in1fmt, ADDR command
.while command != "s"
.if command == "e"
INVOKE printf, ADDR msg1fmt, ADDR msg2
INVOKE scanf, ADDR in2fmt, ADDR number
enqueue
.elseif command=="d"
dequeue
.if number > 0
INVOKE printf, ADDR msg3fmt, ADDR msg3, number
.endif
.else
INVOKE printf, ADDR errfmt, ADDR errmsg1
.endif
INVOKE printf, ADDR msg1fmt, ADDR msg1
INVOKE scanf, ADDR in1fmt, ADDR command
.endw
INVOKE printf, ADDR msg4fmt
ret
main endp
end
.listall
.386
.model flat, c
.stack 1000h
scanf PROTO arg2: Ptr Byte, inputlist: VARARG
printf PROTO arg1: Ptr Byte, printflist: VARARG
.data
in1fmt byte "%s", 0
in2fmt byte "%d", 0
msg1fmt byte 0Ah, "%s", 0
msg3fmt byte 0Ah, "%s%d", 0Ah, 0
msg4fmt byte 0Ah, 0
errfmt byte 0Ah, "%s", 0Ah, 0
msg1 byte "Enter a command, e, d, or s: ", 0
msg2 byte "Enter a positive integer: ", 0
msg3 byte "Te integerr is : ", 0
errmsg1 byte "Error: Invalid entry, try again", 0
errmsg2 byte "Error: Queue is full", 0
errmsg3 byte "Error: Queue is empty", 0
queue sdword 3 dup(7)
command sdword ?
number sdword 0
count sdword 0
.code
main proc
mov edi, offset queue + 0
mov esi, offset queue + 0
INVOKE printf, ADDR msg1fmt, ADDR msg1
INVOKE scanf, ADDR in1fmt, ADDR command
while01: cmp command, "s"
je endw01
if01: cmp command, "e"
jne else01
then01: INVOKE printf, ADDR msg1fmt, ADDR msg2
INVOKE scanf, ADDR in2fmt, ADDR number
if05: cmp count,lengthof queue
jge else05
then05: inc count
mov eax, number
mov [edi], eax
mov eax, edi
sub eax, offset queue
add eax, 4
cdq
mov ecx, sizeof queue
idiv ecx
mov edi, offset queue
add edi, edx
jmp endif05
else05: INVOKE printf, ADDR errfmt, ADDR errmsg2
endif05: nop
jmp endif01
else01: nop
if02: cmp command, "d"
jne else02
then02: nop
if04 : cmp count, 0
jle else04
then04 : nop
dec count
mov eax, [esi]
mov number, eax
mov eax, esi
sub eax, offset queue
add eax, 4
cdq
mov ecx, sizeof queue
idiv ecx
mov esi, offset queue
add esi, edx
jmp endif04
else04 : INVOKE printf, ADDR errfmt, ADDR errmsg3
mov number, -1
endif04 : nop
if03: cmp number, 0
jle endif02
then03: INVOKE printf, ADDR msg3fmt, ADDR msg3, number
jmp endif02
endif03: nop
else02: INVOKE printf, ADDR errfmt, ADDR errmsg1
endif02: nop
endif01 : nop
INVOKE printf, ADDR msg1fmt, ADDR msg1
INVOKE scanf, ADDR in1fmt, ADDR command
jmp while01
endw01: nop
INVOKE printf, ADDR msg4fmt
ret
main endp
end
void enqueue()
{
if (count < n)
{
count++;
queue[rear] = number;
rear=(rear+1)%n
}
}
这个真没有 或许是书里写错了 敢问endif加在哪里啊