汇编中三个整数相减 (MASM)

发布于 2024-10-17 19:28:13 字数 627 浏览 2 评论 0原文

使用AddSub程序,编写一个仅使用16位寄存器减去三个整数的程序。插入call DumpRegs语句以显示寄存器值。

AddSub 示例程序:

TITLE Add and Subtract, Version 2 (AddSub2.asm)
; This program adds and subtracts 32-bit unsigned
; integers and stores the sum in a variable.
INCLUDE Irvine32.inc
.data
val1 DWORD 10000h
val2 DWORD 40000h
val3 DWORD 20000h
finalVal DWORD ?
.code
main PROC
mov eax,val1 ; start with 10000h
add eax,val2 ; add 40000h
sub eax,val3 ; subtract 20000h
mov finalVal,eax ; store the result (30000h)
call DumpRegs ; display the registers
exit
main ENDP
END main
How does it work? First,

Using the AddSub program, write a program that subtracts three integers using only 16-bit registers. Insert a call DumpRegs statement to display the register values.

AddSub Example Program:

TITLE Add and Subtract, Version 2 (AddSub2.asm)
; This program adds and subtracts 32-bit unsigned
; integers and stores the sum in a variable.
INCLUDE Irvine32.inc
.data
val1 DWORD 10000h
val2 DWORD 40000h
val3 DWORD 20000h
finalVal DWORD ?
.code
main PROC
mov eax,val1 ; start with 10000h
add eax,val2 ; add 40000h
sub eax,val3 ; subtract 20000h
mov finalVal,eax ; store the result (30000h)
call DumpRegs ; display the registers
exit
main ENDP
END main
How does it work? First,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

唔猫 2024-10-24 19:28:13

如果不知道“addSub”程序,您可能只需要知道有符号整数(二进制补码)和 0-x 的操作码背后的理论。 (NEG)

八位示例,5-10-20

ldi a,5
ldi b,10
ldi c,20

neg b
neg c
addc a,b
addc a,c

可以吗?

Without knowing the "addSub"-program, you probably only have to know the theory behind signed integers, (two's complement), and the opcode for 0-x. (NEG)

Eight bit example, 5-10-20

ldi a,5
ldi b,10
ldi c,20

neg b
neg c
addc a,b
addc a,c

ok?

天生の放荡 2024-10-24 19:28:13

问题是:以3.2节中的ADDSUB程序为参考,编写一个只对16位寄存器进行三个整数相减的程序。插入一个 cal DumpRegs 语句来显示寄存器值

工作是:

TITLE Add and Subtract      (AddSub.asm)

; Program Assignment 1 - Subtracting Three Integers   
; Using the AddSub program From Section 3.2 as a Reference,  
; Write a program that subtracts three Integer using only 16-bit     registers,  
; Insert a call DumpRegs statement to display the register values.

INCLUDE Irvine32.inc

 .code
 main PROC

 mov eax, 90000h    ;EAX = 10000h  
 sub eax, 40000h    ;EAX = 50000h   
 sub eax, 20000h    ;EAX = 30000h   
 call DumpRegs                ; display registers    

   exit    

   main ENDP   

   END main

Question is:Using the ADDSUB program from the section 3.2 as a reference, write a program that subtracts three integers only 16-bit registers. Insert a cal DumpRegs statement to display the register values

Work is:

TITLE Add and Subtract      (AddSub.asm)

; Program Assignment 1 - Subtracting Three Integers   
; Using the AddSub program From Section 3.2 as a Reference,  
; Write a program that subtracts three Integer using only 16-bit     registers,  
; Insert a call DumpRegs statement to display the register values.

INCLUDE Irvine32.inc

 .code
 main PROC

 mov eax, 90000h    ;EAX = 10000h  
 sub eax, 40000h    ;EAX = 50000h   
 sub eax, 20000h    ;EAX = 30000h   
 call DumpRegs                ; display registers    

   exit    

   main ENDP   

   END main
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文