AdvancedArithmetic - Advanced Arithmetic Advanced...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Advanced Arithmetic Beta Draft - Do not distribute © 2001, By Randall Hyde Page 853 Ad vanced Arithmetic Chapter Four 4.1 Chapter Overview This chapter deals with those arithmetic operations for which assembly language is especially well suited and high le v el languages are, in general, poorly suited. It co v ers three main topics: e xtended precision arithmetic, arithmetic on operands who sizes are dif ferent, and decimal arithmetic. By f ar , the most e xtensi v e subject this chapter co v ers is multi-precision arithmetic. By the conclusion of this chapter you will kno w ho w to apply arithmetic and logical operations to inte ger operands of an y size. If you need to w ork with inte ger v alues outside the range ±2 billion (or with unsigned v alues be yond four bil - lion), no sweat; this chapter will sho w you ho w to get the job done. Operands whose sizes are not the same also present some special problems in arithmetic operations. F or e xample, you may w ant to add a 128-bit unsigned inte ger to a 256-bit signed inte ger v alue. This chapter discusses ho w to con v ert these tw o operands to a compatible format so the operation may proceed. Finally , this chapter discusses decimal arithmetic using the BCD (binary coded decimal) features of the 80x86 instruction set and the FPU. This lets you use decimal arithmetic in those fe w applications that abso - lutely require base 10 operations (rather than binary). 4.2 Multiprecision Operations One big adv antage of assembly language o v er high le v el languages is that assembly language does not limit the size of inte ger operations. F or e xample, the C programming language defi nes a maximum of three dif ferent inte ger sizes: short int, int, and long int 1 . On the PC, these are often 16 and 32 bit inte gers. Although the 80x86 machine instructions limit you to processing eight, sixteen, or thirty-tw o bit inte gers with a single instruction, you can al w ays use more than one instruction to process inte gers of an y size you desire. If you w ant to add 256 bit inte ger v alues together , no problem, it’ s relati v ely easy to accomplish this in assembly language. The follo wing sections describe ho w e xtended v arious arithmetic and logical opera - tions from 16 or 32 bits to as man y bits as you please. 4.2.1 Multiprecision Addition Operations The 80x86 ADD instruction adds tw o eight, sixteen, or thirty-tw o bit numbers 2 . After the e x ecution of the add instruction, the 80x86 carry fl ag is set if there is an o v erfl o w out of the H.O. bit of the sum. Y ou can use this information to do multiprecision addition operations. Consider the w ay you manually perform a multidigit (multiprecision) addition operation: Step 1: Add the least significant digits together: 289 +456 produces +456 ---- 5 with carry 1.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/08/2011 for the course CS 101 taught by Professor Jitenderkumarchhabra during the Summer '11 term at National Institute of Technology, Calicut.

Page1 / 56

AdvancedArithmetic - Advanced Arithmetic Advanced...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online